From daecce8571a0a27a6c758cad2185faa6df83679a Mon Sep 17 00:00:00 2001 From: Matthew Brooks Date: Mon, 6 Aug 2018 17:46:37 -0400 Subject: [PATCH] Added a test for a simple loop --- .gitignore | 3 ++- PROGRAMS | 44 -------------------------------- blackbox_test.py | 11 ++++---- src/instructions/instructions.c | 1 + src/mbvm.c | 6 ++--- test_programs/loop | Bin 0 -> 36 bytes 6 files changed, 12 insertions(+), 53 deletions(-) delete mode 100644 PROGRAMS create mode 100644 test_programs/loop diff --git a/.gitignore b/.gitignore index b486a88..99ff2b5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ exec/ cmake*/* .idea/ venv/ -lbuild/ \ No newline at end of file +lbuild/ +/programs.txt diff --git a/PROGRAMS b/PROGRAMS deleted file mode 100644 index 8ae8cbb..0000000 --- a/PROGRAMS +++ /dev/null @@ -1,44 +0,0 @@ -// Loops 10 times adding 5 to r1 each time then printing contents -0x0101000A, -0x020A0002, -0x010A0001, -0x020A0009, -0xFE000000, -0x0101000A, -0x020A0009, -0xFE000000, -0x010A0001, -0x03010005, -0x020A0001, -0x010A0002, -0x04010001, -0x020A0002, -0x100B0000, -0x00000004, -0x00000000 - -// Hello World -0x01010010, -0x020A0009, -0xFEFF0000, -0x00000000, -0x68656C6C, // The string 'hello world\n' -0x6F20776F, -0x726C640A, - -// Testing -0x01010005, // LOAD.ib 0x05 (Load immediate byte 0x05 into dr) -0x020A0000, // STORE.r 0x00 (Store into register 0x00 contents of dr) -0x030A0000, // ADD.r 0x00 (Add contents of register 0x00 with contents of dr) -0x020A0009, // STORE.r 0x09 (Store into pr the contents of dr) -0xFE000000, // PRINT -- (Print the pr) -0x020A0000, // STORE.r 0x00 (Store into register 0x00 contents of dr) -0x04010009, // SUB.ib 0x09 (Subtract 0x09 from contents of dr) -0x020A0000, // STORE.r 0x00 (Store into register 0x00 contents of dr) -0x020A0009, // STORE.r 0x09 (Store into pr the contents of dr) -0xFE000000, // PRINT -- (Print the pr) -0xFD000000, // SCAN -- (Scan into the pr) -0x0101000B, // LOAD.ib 0x0B (Load immediate byte 0x0B into dr) -0xFDFF0000, // SCAN -- (...) -0xFF000000, // NOOP -0x00000000, // Exit \ No newline at end of file diff --git a/blackbox_test.py b/blackbox_test.py index 73cdffd..b6770c0 100644 --- a/blackbox_test.py +++ b/blackbox_test.py @@ -29,14 +29,14 @@ def test_program(program_name, expected_output): if not isinstance(received_output, str): received_output = received_output.decode("utf-8") - print("testing '" + program_name + "'... ", end="") + print("testing '{}'... ".format(program_name), end="") if expected_output == received_output: print("passed") return 0 else: - print("failed! '" + received_output + "' != '" + expected_output + "'") + print("failed! '{}' != '{}'".format(received_output, expected_output)) return 1 @@ -49,11 +49,12 @@ def main(): """ failed_tests = 0 - failed_tests += test_program("hello_world", "hello world! \n") + failed_tests += test_program("hello_world", "hello world!\n") + failed_tests += test_program("loop", "*") # TODO: Add more test cases here... if failed_tests: - print("Errors: Failed '" + str(failed_tests) + "' tests!") + print("Errors: Failed '{}' tests!".format(str(failed_tests))) else: print("All tests passed!") @@ -77,7 +78,7 @@ def main(): mbvm_exec = mbvm_unix_exec if not mbvm_exec: - sys.stderr.write("ERROR: Could not find the mbvm executable.") + sys.stderr.write("ERROR: Could not find the mbvm executable") sys.exit(1) if __name__ == "__main__": diff --git a/src/instructions/instructions.c b/src/instructions/instructions.c index 2556f9b..eb0f05e 100644 --- a/src/instructions/instructions.c +++ b/src/instructions/instructions.c @@ -600,6 +600,7 @@ void instr_jmp(struct instruction ic) // TODO: add the other jump modes mem_addr = get_dword(ram, incr_pc()); + // TODO: I don't think this will always be true if ((mem_addr % INSTRUCTION_SIZE) == 0) { switch (ic.mode) diff --git a/src/mbvm.c b/src/mbvm.c index 2cfdd53..38568bf 100644 --- a/src/mbvm.c +++ b/src/mbvm.c @@ -58,7 +58,7 @@ int parse_args(int argc, const char *argv[]) int main(int argc, const char *argv[]) { if (parse_args(argc, argv) != 0) - return 1; + return EXIT_FAILURE; // Create the virtual machine in RAM // TODO: Take VM init values as command line arguments @@ -69,7 +69,7 @@ int main(int argc, const char *argv[]) if (0 != load_file(file_name)) { printf("ERROR: Failed to open file '%s'.", file_name); - return 1; + return EXIT_FAILURE; } // Pass the program to the virtual machine and begin executing @@ -77,5 +77,5 @@ int main(int argc, const char *argv[]) // Free all the memory we allocated deallocate_vm(); - return 0; + return EXIT_SUCCESS; } diff --git a/test_programs/loop b/test_programs/loop new file mode 100644 index 0000000000000000000000000000000000000000..44204924dd2490c908b83523c1eb7e971719018c GIT binary patch literal 36 gcmZQ%WME|GVqjnbViraQEdg!@Fkpm;asC7H01j6Hg#Z8m literal 0 HcmV?d00001