Skip to content

Commit

Permalink
added code to pass down variables and fixed small bugs. Resolves Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
SonikaG committed Nov 10, 2017
1 parent 3a3b816 commit 0afa93f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
6 changes: 6 additions & 0 deletions code/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ MODULES = cow_brd disk_wrapper
obj-m := $(addsuffix .o, $(MODULES))
KDIR := /lib/modules/$(shell uname -r)/build

CM_TESTS_EXCLUDE = BaseTestCase.cpp
CM_TESTS = $(patsubst %.cpp, %.so, $(notdir $(wildcard $(CURDIR)/tests/*.cpp)))
CM_TESTS = \
$(patsubst %.cpp, %.so, \
$(filter-out $(CM_TESTS_EXCLUDE), \
$(notdir $(wildcard $(CURDIR)/tests/*.cpp))))
CM_PERMUTER_EXCLUDE = Permuter.cpp
CM_PERMUTERS = \
$(patsubst %.cpp, %.so, \
Expand Down Expand Up @@ -87,6 +92,7 @@ $(BUILD_DIR)/c_harness: \

$(BUILD_DIR)/tests/%.so: \
tests/%.cpp \
$(BUILD_DIR)/tests/BaseTestCase.o \
$(BUILD_DIR)/user_tools/src/actions.o \
$(BUILD_DIR)/utils/communication/BaseSocket.o \
$(BUILD_DIR)/utils/communication/ClientSocket.o \
Expand Down
4 changes: 2 additions & 2 deletions code/harness/Tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ int Tester::test_setup() {
return test_loader.get_instance()->setup();
}

int Tester::test_pass(string mountDir, string filesysSize){
return test_loader.get_instance()->pass(mountDir, filesysSize);
int Tester::test_pass(string mount_dir, string filesys_size){
return test_loader.get_instance()->pass(mount_dir, filesys_size);
}

int Tester::test_run() {
Expand Down
15 changes: 10 additions & 5 deletions code/harness/c_harness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@ int main(int argc, char** argv) {
****************************************************************************/
const unsigned int test_case_idx = optind;
const string path = argv[test_case_idx];
cout << test_dev << endl;
if(!(setenv("MOUNT_FS", test_dev.c_str(), 1))){
//this should be changed in the option is added to mount tests in other directories
string mount_dir = "/mnt/snapshot";
if(setenv("MOUNT_FS", mount_dir.c_str(), 1) == -1){
cerr << "Error setting environment variable MOUNT_FS" << endl;
}

//input file created to read output from bash command "df"
FILE *input;
char buf[512];
if(!(input = popen(("df --output=source,size | grep " + flags_dev).c_str(), "r"))){
Expand All @@ -151,9 +154,9 @@ int main(int argc, char** argv) {
while(fgets(buf, 512, input)){
filesize += buf;
}
//fileSysSize = filesize;
pclose(input);
if(!setenv("FILESYS_SIZE", filesize.c_str(), 1)){

if(setenv("FILESYS_SIZE", filesize.c_str(), 1) == -1){
cerr << "Error setting environment variable FILESYS_SIZE" << endl;
}
cout << "========== PHASE 0: Setting up CrashMonkey basics =========="
Expand Down Expand Up @@ -229,14 +232,16 @@ int main(int argc, char** argv) {
}
test_harness.set_fs_type(fs_type);
test_harness.set_device(test_dev);
test_harness.test_pass(test_dev, filesize);

// Load the class being tested.
cout << "Loading test case" << endl;
if (test_harness.test_load_class(argv[test_case_idx]) != SUCCESS) {
test_harness.cleanup_harness();
return -1;
}

test_harness.test_pass(mount_dir, filesize);

// Load the permuter to use for the test.
// TODO(ashmrtn): Consider making a line in the test file which specifies the
// permuter to use?
Expand Down
15 changes: 15 additions & 0 deletions code/tests/BaseTestCase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "BaseTestCase.h"

namespace fs_testing {
namespace tests {

using std::string;

int BaseTestCase::pass(string mount_dir, string filesys_size) {
mnt_dir_ = mount_dir;
filesys_size_ = filesys_size;
return 0;
}

} // namespace tests
} // namespace fs_testing
11 changes: 8 additions & 3 deletions code/tests/BaseTestCase.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TEST_CASE_H
#define TEST_CASE_H
#ifndef BASE_TEST_CASE_H
#define BASE_TEST_CASE_H

#include "../results/DataTestResult.h"
#include <string>
Expand All @@ -13,11 +13,16 @@ class BaseTestCase {
virtual int run() = 0;
virtual int check_test(unsigned int last_checkpoint,
DataTestResult *test_result) = 0;
virtual int pass(std::string mountDir, std::string filesysSize) {}
virtual int pass(std::string mount_dir, std::string filesys_size);

protected:
std::string mnt_dir_;
std::string filesys_size_;
};

typedef BaseTestCase *test_create_t();
typedef void test_destroy_t(BaseTestCase *instance);

} // namespace tests
} // namespace fs_testing

Expand Down
3 changes: 0 additions & 3 deletions code/tests/rename_root_to_sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ class rename_root_to_sub : public BaseTestCase {

return 0;
}
virtual int pass(std::string mountDir, std::string filesysSize){
std::cout << mountDir << " " << filesysSize << std::endl;
}

private:
char text[strlen(TEST_TEXT)];
Expand Down

0 comments on commit 0afa93f

Please sign in to comment.