From f61ff09c45035393073ba1d06250f70f594488d4 Mon Sep 17 00:00:00 2001 From: Nicola Date: Wed, 3 Apr 2024 12:55:19 +0200 Subject: [PATCH 01/29] Build and run tasks for VScode --- .vscode/tasks.json | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..66d4455 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,58 @@ + +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build all tests", + "type": "shell", + "command": "echo ${cwd} && make compile", + "presentation": { + "reveal": "never" + }, + "problemMatcher": { + "owner": "make", + "fileLocation": [ + "relative", + "${workspaceFolder}" + ], + "pattern": { + "regexp": "Running test (.+)... ( )+(FAIL|TIME OUT)", + "file": 1 + } + }, + "options": { + "cwd": "${fileDirname}" + }, + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "label": "Run all tests", + "type": "shell", + "command": "echo ${cwd} && make all", + "presentation": { + "reveal": "never" + }, + "problemMatcher": { + "owner": "make", + "fileLocation": [ + "relative", + "${workspaceFolder}" + ], + "pattern": { + "regexp": "Running test (.+)... ( )+(FAIL|TIME OUT)", + "file": 1 + } + }, + "options": { + "cwd": "${fileDirname}" + }, + "group": { + "kind": "build", + "isDefault": false + } + } + ] +} \ No newline at end of file From 9317c547d0c1c78911f95dddc3450da92ce1c1d8 Mon Sep 17 00:00:00 2001 From: Nicola Date: Wed, 3 Apr 2024 12:55:38 +0200 Subject: [PATCH 02/29] added example to test build and run tasks --- Makefile | 2 +- ex/example11.expected | 2 ++ ex/example11/Makefile | 3 +++ ex/example11/implementation.c | 6 ++++++ ex/example11/implementation.h | 5 +++++ ex/example11/tests/test0.c | 8 ++++++++ ex/example11/tests/test1.c | 10 ++++++++++ 7 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 ex/example11.expected create mode 100644 ex/example11/Makefile create mode 100644 ex/example11/implementation.c create mode 100644 ex/example11/implementation.h create mode 100644 ex/example11/tests/test0.c create mode 100644 ex/example11/tests/test1.c diff --git a/Makefile b/Makefile index 145a7ee..610acd4 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ all: all-examples EXAMPLES = ex/example1 ex/example2 ex/example3 ex/example4 \ - ex/example5 ex/example6 ex/example7 ex/example8 \ + ex/example5 ex/example6 ex/example7 ex/example8 ex/example11 \ 'ex ws/example1 ws' 'ex ws/example2 ws' 'ex ws/example3 ws' 'ex ws/example4 ws' \ 'ex ws/example5 ws' 'ex ws/example6 ws' 'ex ws/example7 ws' 'ex ws/example8 ws' diff --git a/ex/example11.expected b/ex/example11.expected new file mode 100644 index 0000000..f66c147 --- /dev/null +++ b/ex/example11.expected @@ -0,0 +1,2 @@ +Running test test0... PASS +Running test test1... PASS \ No newline at end of file diff --git a/ex/example11/Makefile b/ex/example11/Makefile new file mode 100644 index 0000000..e3e112e --- /dev/null +++ b/ex/example11/Makefile @@ -0,0 +1,3 @@ +OBJECTS=implementation.o + +include ../../basic_testing.mk diff --git a/ex/example11/implementation.c b/ex/example11/implementation.c new file mode 100644 index 0000000..d2f9f6d --- /dev/null +++ b/ex/example11/implementation.c @@ -0,0 +1,6 @@ +#include "implementation.h" + +int init_foo(struct foo* data) { + data->character = '0'; + return 1; +} \ No newline at end of file diff --git a/ex/example11/implementation.h b/ex/example11/implementation.h new file mode 100644 index 0000000..b6861d8 --- /dev/null +++ b/ex/example11/implementation.h @@ -0,0 +1,5 @@ +struct foo { + char character; +}; + +int init_foo(struct foo*); \ No newline at end of file diff --git a/ex/example11/tests/test0.c b/ex/example11/tests/test0.c new file mode 100644 index 0000000..46babb7 --- /dev/null +++ b/ex/example11/tests/test0.c @@ -0,0 +1,8 @@ +#include "basic_testing.h" +#include "../implementation.h" + +TEST(compile) { + TEST_PASSED; +} + +MAIN_TEST_DRIVER(compile); \ No newline at end of file diff --git a/ex/example11/tests/test1.c b/ex/example11/tests/test1.c new file mode 100644 index 0000000..a3ca2b2 --- /dev/null +++ b/ex/example11/tests/test1.c @@ -0,0 +1,10 @@ +#include "basic_testing.h" +#include "../implementation.h" + +TEST(initialize) { + struct foo data; + int result = init_foo(&data); + TEST_PASSED; +} + +MAIN_TEST_DRIVER(initialize); \ No newline at end of file From b727cb24dd3b12bb5da6bc1a0bb46f919ce787a2 Mon Sep 17 00:00:00 2001 From: Nicola Date: Wed, 10 Apr 2024 08:12:52 +0200 Subject: [PATCH 03/29] Refined tasks --- .vscode/tasks.json | 108 +++++++++++++++++++--------------- ex/example11/implementation.c | 1 + ex/example11/tests/fail.c | 11 ++++ ex/example11/tests/test0.c | 15 ++++- ex/example11/tests/timeout.c | 10 ++++ 5 files changed, 97 insertions(+), 48 deletions(-) create mode 100644 ex/example11/tests/fail.c create mode 100644 ex/example11/tests/timeout.c diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 66d4455..b94ba5e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,58 +1,72 @@ { - "version": "2.0.0", - "tasks": [ - { - "label": "Build all tests", - "type": "shell", - "command": "echo ${cwd} && make compile", - "presentation": { - "reveal": "never" - }, - "problemMatcher": { - "owner": "make", - "fileLocation": [ +"version": "2.0.0", +"tasks": [ + { + "label": "Build implementation", + "type": "shell", + "command": "make compile", + "presentation": { + "reveal": "never" + }, + // Allows for the definition of a regexp, which matches the output of the command when some problem occurs; + // these get reported in the "problems" tab of VScode + "problemMatcher": { + "owner": "basic_testing", + "fileLocation":[ "relative", - "${workspaceFolder}" + "${fileDirname}/" ], - "pattern": { - "regexp": "Running test (.+)... ( )+(FAIL|TIME OUT)", - "file": 1 - } - }, - "options": { - "cwd": "${fileDirname}" - }, - "group": { - "kind": "build", - "isDefault": false - } + "pattern": [ + { + // Matches "tests/test1.c:6:9: warning: unused variable ‘result’ [-Wunused-variable]" + "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + }] + }, + "options": { + "cwd": "${fileDirname}" }, - { - "label": "Run all tests", - "type": "shell", - "command": "echo ${cwd} && make all", - "presentation": { - "reveal": "never" - }, - "problemMatcher": { + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "label": "Run all tests", + "type": "shell", + "command": "make all", + "presentation": { + "reveal": "never" + }, + "problemMatcher": [ + { "owner": "make", - "fileLocation": [ + "fileLocation":[ "relative", - "${workspaceFolder}" + "${fileDirname}/tests/" ], - "pattern": { - "regexp": "Running test (.+)... ( )+(FAIL|TIME OUT)", - "file": 1 - } - }, - "options": { - "cwd": "${fileDirname}" - }, - "group": { - "kind": "build", - "isDefault": false + "pattern": + { + // Matches "Running test test_name... FAIL" + "regexp": "^Running test\\s(.+)\\.\\.\\.\\s+FAIL$", + "file": 1, + "message": 1, + "kind": "file" + }, } + ], + "options": { + "cwd": "${fileDirname}" + }, + "group": { + "kind": "build", + "isDefault": false } - ] + } +] } \ No newline at end of file diff --git a/ex/example11/implementation.c b/ex/example11/implementation.c index d2f9f6d..e7b8d8b 100644 --- a/ex/example11/implementation.c +++ b/ex/example11/implementation.c @@ -1,6 +1,7 @@ #include "implementation.h" int init_foo(struct foo* data) { + int result = 1; data->character = '0'; return 1; } \ No newline at end of file diff --git a/ex/example11/tests/fail.c b/ex/example11/tests/fail.c new file mode 100644 index 0000000..4e16109 --- /dev/null +++ b/ex/example11/tests/fail.c @@ -0,0 +1,11 @@ +#include "basic_testing.h" + +TEST(fail) { + TEST_FAILED; +} + +TEST(fail_second) { + TEST_FAILED; +} + +MAIN_TEST_DRIVER(fail, fail_second); \ No newline at end of file diff --git a/ex/example11/tests/test0.c b/ex/example11/tests/test0.c index 46babb7..7a3e285 100644 --- a/ex/example11/tests/test0.c +++ b/ex/example11/tests/test0.c @@ -5,4 +5,17 @@ TEST(compile) { TEST_PASSED; } -MAIN_TEST_DRIVER(compile); \ No newline at end of file +TEST(with_variable) { + int variable = 0; + variable++; + TEST_PASSED; +} + +TEST(fail) { + if (1) { + TEST_FAILED; + } + TEST_PASSED; +} + +MAIN_TEST_DRIVER(compile, with_variable, fail); \ No newline at end of file diff --git a/ex/example11/tests/timeout.c b/ex/example11/tests/timeout.c new file mode 100644 index 0000000..0ce4ef7 --- /dev/null +++ b/ex/example11/tests/timeout.c @@ -0,0 +1,10 @@ +#include "basic_testing.h" +#include + + +TEST(timeout) { + sleep(10); + TEST_PASSED; +} + +MAIN_TEST_DRIVER(timeout); \ No newline at end of file From 70f51339b6ea75d717bc0490bce1042f7f3e1e15 Mon Sep 17 00:00:00 2001 From: Nicola Date: Wed, 10 Apr 2024 08:13:49 +0200 Subject: [PATCH 04/29] Added basic debugger (gdb) integration --- .vscode/launch.json | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..efadab1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,30 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "bt debug (gdb)", + "type": "cppdbg", + "request": "launch", + "cwd": "${fileDirname}", + "preLaunchTask": "Run all tests", + "program": "${fileDirname}/${fileBasenameNoExtension}", + "args": ["-d"], + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + } + ] +} \ No newline at end of file From 69077394dff8a387769a0109920e81b05543b093 Mon Sep 17 00:00:00 2001 From: Nicola Date: Wed, 10 Apr 2024 08:57:46 +0200 Subject: [PATCH 05/29] Fixed predebug test build --- .vscode/launch.json | 2 +- .vscode/tasks.json | 12 ++++++++++++ basic_testing.mk | 25 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index efadab1..a7b10a1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "cppdbg", "request": "launch", "cwd": "${fileDirname}", - "preLaunchTask": "Run all tests", + "preLaunchTask": "Build single test", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": ["-d"], "MIMode": "gdb", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b94ba5e..6809138 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -67,6 +67,18 @@ "kind": "build", "isDefault": false } + }, + { + "label": "Build single test", + "detail": "To be run from a test file in a tests directory, and the Makefile in its parent directory", + "type": "shell", + "presentation": { + "reveal": "never" + }, + "options": { + "cwd": "${fileDirname}/../" + }, + "command": "make check-single-bin BIN_NAME=tests/${fileBasenameNoExtension}" } ] } \ No newline at end of file diff --git a/basic_testing.mk b/basic_testing.mk index b6f8bdf..0ab4532 100644 --- a/basic_testing.mk +++ b/basic_testing.mk @@ -208,6 +208,31 @@ check-bin: $(TESTS_BIN) done; \ test_summary 'Summary: PASS ' +.PHONY: check-single-bin +check-single-bin: $(BIN_NAME) + @exec 2> /dev/null; \ + if test -z $$BIN_NAME; then \ + echo "Error: Missing test to run, please set BIN_NAME="; \ + echo " example: \`make check-single-bin BIN_NAME=tests/test0\`"; \ + exit 1; fi; \ + $(SCRIPT_INIT); \ + t=$$BIN_NAME; \ + test_start "$$t"; \ + if test -n "$(WITH_VALGRIND)"; then \ + echo ;\ + valgrind $(VALGRIND_FLAGS) "$(TESTS_DIR)/$$t" 2>&1 &\ + else \ + "$(TESTS_DIR)/$$t" $(BIN_FLAGS) &\ + fi; \ + $(SCRIPT_GET_TEST_RESULT); \ + if test $$res = KO; then \ + test_diag "run '$(TESTS_DIR)/$$t' to see what went wrong" ; \ + test_diag "run '$(TESTS_DIR)/$$t -d' with a debugger" ; \ + else \ + test_ok PASS; \ + fi; \ + test_summary 'Summary: PASS ' + .PHONY: clean clean: rm -f $(PROGRAMS) *-valgrind $(OBJECTS) tests/*.o $(TESTS_BIN) \ From c3998b2534b6476618cadb344234e18e14063e02 Mon Sep 17 00:00:00 2001 From: Nicola Date: Wed, 10 Apr 2024 18:39:54 +0200 Subject: [PATCH 06/29] Added problem matcher for building single test --- .vscode/tasks.json | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 6809138..19fbd35 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -78,7 +78,24 @@ "options": { "cwd": "${fileDirname}/../" }, - "command": "make check-single-bin BIN_NAME=tests/${fileBasenameNoExtension}" + "command": "make check-single-bin BIN_NAME=tests/${fileBasenameNoExtension}", + "problemMatcher": [ + { + "owner": "make", + "fileLocation":[ + "relative", + "${fileDirname}/tests/" + ], + "pattern": + { + // Matches "Running test test_name... FAIL" + "regexp": "^Running test\\s(.+)\\.\\.\\.\\s+FAIL$", + "file": 1, + "message": 1, + "kind": "file" + }, + } + ], } ] } \ No newline at end of file From 452738ff033198105347e055d5af45c097fba7e1 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Fri, 12 Apr 2024 16:39:48 +0200 Subject: [PATCH 07/29] added selection for debugger --- .vscode/launch.json | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index a7b10a1..cf85b25 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ "preLaunchTask": "Build single test", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": ["-d"], - "MIMode": "gdb", + "MIMode": "${input:debugger}", "setupCommands": [ { "description": "Enable pretty-printing for gdb", @@ -26,5 +26,17 @@ } ], } - ] -} \ No newline at end of file + ], + "inputs": [ + { + "type": "pickString", + "id": "debugger", + "description": "Which debugger do you want to use?", + "options": [ + "gdb", + "lldb", + ], + "default": "gdb" + }, + ], +} From ece69b3019ef5785cd2f66db13686d7ce4a8c03a Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Mon, 15 Apr 2024 16:30:12 +0200 Subject: [PATCH 08/29] updated config for vscode and minor fix in makefile --- .vscode/launch.json | 12 ++++++++++-- .vscode/tasks.json | 4 ++-- basic_testing.mk | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index cf85b25..2351b75 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,14 @@ "version": "0.2.0", "configurations": [ { - "name": "bt debug (gdb)", + "name": "Run all tests", + "type": "extensionHost", + "preLaunchTask": "Run all tests", + "request":"launch", + // "program": + }, + { + "name": "debug current test (gdb)", "type": "cppdbg", "request": "launch", "cwd": "${fileDirname}", @@ -25,7 +32,8 @@ "ignoreFailures": true } ], - } + }, + ], "inputs": [ { diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 19fbd35..b8c8675 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -5,7 +5,7 @@ { "label": "Build implementation", "type": "shell", - "command": "make compile", + "command": " touch ${file}; make compile", "presentation": { "reveal": "never" }, @@ -98,4 +98,4 @@ ], } ] -} \ No newline at end of file +} diff --git a/basic_testing.mk b/basic_testing.mk index 0ab4532..f095f1f 100644 --- a/basic_testing.mk +++ b/basic_testing.mk @@ -212,7 +212,7 @@ check-bin: $(TESTS_BIN) check-single-bin: $(BIN_NAME) @exec 2> /dev/null; \ if test -z $$BIN_NAME; then \ - echo "Error: Missing test to run, please set BIN_NAME="; \ + echo "Error: Missing test to run, please set BIN_NAME="; \ echo " example: \`make check-single-bin BIN_NAME=tests/test0\`"; \ exit 1; fi; \ $(SCRIPT_INIT); \ From 810a6df5c547194961cc653bc5a31bb451361b90 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Wed, 17 Apr 2024 17:42:00 +0200 Subject: [PATCH 09/29] Modified VScode configuration single default task to build and run tests, automatically checks if (Note; maybe requires bash as a shell, or equivalent + cd and touch) --- .vscode/launch.json | 9 ++---- .vscode/tasks.json | 57 ++++++++--------------------------- ex/example11/implementation.c | 2 +- ex/example11/tests/fail.c | 3 +- ex/example11/tests/test0.c | 9 +----- 5 files changed, 19 insertions(+), 61 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 2351b75..92e8ad9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,21 +4,16 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - { - "name": "Run all tests", - "type": "extensionHost", - "preLaunchTask": "Run all tests", - "request":"launch", - // "program": - }, { "name": "debug current test (gdb)", + // Requires C/C++ extension from Microsoft "type": "cppdbg", "request": "launch", "cwd": "${fileDirname}", "preLaunchTask": "Build single test", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": ["-d"], + // Requires C/C++ extension from Microsoft "MIMode": "${input:debugger}", "setupCommands": [ { diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b8c8675..a7b8470 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -3,47 +3,17 @@ "version": "2.0.0", "tasks": [ { - "label": "Build implementation", + "label": "Build and run tests", + "detail": "Runs all tests, or a single test when opened in the editor", "type": "shell", - "command": " touch ${file}; make compile", "presentation": { "reveal": "never" }, - // Allows for the definition of a regexp, which matches the output of the command when some problem occurs; - // these get reported in the "problems" tab of VScode - "problemMatcher": { - "owner": "basic_testing", - "fileLocation":[ - "relative", - "${fileDirname}/" - ], - "pattern": [ - { - // Matches "tests/test1.c:6:9: warning: unused variable ‘result’ [-Wunused-variable]" - "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", - "file": 1, - "line": 2, - "column": 3, - "severity": 4, - "message": 5 - }] - }, "options": { - "cwd": "${fileDirname}" - }, - "group": { - "kind": "build", - "isDefault": false - } - }, - { - "label": "Run all tests", - "type": "shell", - "command": "make all", - "presentation": { - "reveal": "never" + "cwd": "${fileDirname}/", }, - "problemMatcher": [ + "command": " if [[ ${fileDirnameBasename} == tests ]]; then touch ${file}; cd .. && make check-single-bin BIN_NAME=tests/${fileBasenameNoExtension}; else touch ${file}; make; fi", + "problemMatcher": ["$gcc", { "owner": "make", "fileLocation":[ @@ -60,26 +30,24 @@ }, } ], - "options": { - "cwd": "${fileDirname}" - }, "group": { "kind": "build", - "isDefault": false + "isDefault": true } }, { "label": "Build single test", - "detail": "To be run from a test file in a tests directory, and the Makefile in its parent directory", + "detail": "Builds and runs a single test (open file in editor)", "type": "shell", "presentation": { - "reveal": "never" + "reveal": "always", + "focus": true }, "options": { - "cwd": "${fileDirname}/../" + "cwd": "${fileDirname}/..", }, "command": "make check-single-bin BIN_NAME=tests/${fileBasenameNoExtension}", - "problemMatcher": [ + "problemMatcher": ["$gcc", { "owner": "make", "fileLocation":[ @@ -95,7 +63,8 @@ "kind": "file" }, } - ], + ] } + ] } diff --git a/ex/example11/implementation.c b/ex/example11/implementation.c index e7b8d8b..8d61712 100644 --- a/ex/example11/implementation.c +++ b/ex/example11/implementation.c @@ -4,4 +4,4 @@ int init_foo(struct foo* data) { int result = 1; data->character = '0'; return 1; -} \ No newline at end of file +} diff --git a/ex/example11/tests/fail.c b/ex/example11/tests/fail.c index 4e16109..70451b4 100644 --- a/ex/example11/tests/fail.c +++ b/ex/example11/tests/fail.c @@ -1,6 +1,7 @@ #include "basic_testing.h" TEST(fail) { + int result = 0; TEST_FAILED; } @@ -8,4 +9,4 @@ TEST(fail_second) { TEST_FAILED; } -MAIN_TEST_DRIVER(fail, fail_second); \ No newline at end of file +MAIN_TEST_DRIVER(fail, fail_second); diff --git a/ex/example11/tests/test0.c b/ex/example11/tests/test0.c index 7a3e285..64932a1 100644 --- a/ex/example11/tests/test0.c +++ b/ex/example11/tests/test0.c @@ -11,11 +11,4 @@ TEST(with_variable) { TEST_PASSED; } -TEST(fail) { - if (1) { - TEST_FAILED; - } - TEST_PASSED; -} - -MAIN_TEST_DRIVER(compile, with_variable, fail); \ No newline at end of file +MAIN_TEST_DRIVER(compile, with_variable); From 0eb183b309fc3d0358980509f26a25ffb85c9034 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Thu, 18 Apr 2024 16:37:13 +0200 Subject: [PATCH 10/29] added CLion local configuration all important information present also in the readme.md --- ex/example11/.idea/.gitignore | 3 +++ ex/example11/.idea/CLion-bt-tools.zip | Bin 0 -> 2094 bytes ex/example11/.idea/README.md | 14 ++++++++++++++ ex/example11/.idea/customTargets.xml | 15 +++++++++++++++ ex/example11/.idea/misc.xml | 18 ++++++++++++++++++ .../runConfigurations/Debug_single_test.xml | 8 ++++++++ ex/example11/.idea/runConfigurations/Run.xml | 7 +++++++ ex/example11/.idea/tools/Basic Testing.xml | 16 ++++++++++++++++ 8 files changed, 81 insertions(+) create mode 100644 ex/example11/.idea/.gitignore create mode 100644 ex/example11/.idea/CLion-bt-tools.zip create mode 100644 ex/example11/.idea/README.md create mode 100644 ex/example11/.idea/customTargets.xml create mode 100644 ex/example11/.idea/misc.xml create mode 100644 ex/example11/.idea/runConfigurations/Debug_single_test.xml create mode 100644 ex/example11/.idea/runConfigurations/Run.xml create mode 100644 ex/example11/.idea/tools/Basic Testing.xml diff --git a/ex/example11/.idea/.gitignore b/ex/example11/.idea/.gitignore new file mode 100644 index 0000000..54d4519 --- /dev/null +++ b/ex/example11/.idea/.gitignore @@ -0,0 +1,3 @@ +/workspace.xml +/vcs.xml +/editor.xml diff --git a/ex/example11/.idea/CLion-bt-tools.zip b/ex/example11/.idea/CLion-bt-tools.zip new file mode 100644 index 0000000000000000000000000000000000000000..7f8a379bebe97bfeb94d838146f17d986394b069 GIT binary patch literal 2094 zcmWIWW@h1HVBlb2&<&at!GHwVfb5d|{G4L_0H7KX1`ZAmhOk0ZHR5nJPKm{t$qFT@ z#U+_}>3S8pIi-Q8^O_9=_B_|t(JrrRPzYQgx{Bk3La1$M^k&Yy-rheMm+NYModZNo z)vMFf!Z&Z;csXj@i;gD2@-KXA9voR%>Li=FNl|4UEB9^IIS)=Q3{*Jj6L4wqQ#T*K zjIE1h-kebFnR3Iie%dOgg<2tX?)(b6aSs-W`_0zgVEBu7=WeHHmc#9C{&i6^<02}i z-dNwTeMV;LRvx*zAH6>_U0qdL`}VHxDuentHJWx3Ymb;OYu}*uIV*GaVvfWIoIig` zbN$`@b&_vbc<8S4nm-v{I@=zqmXP?XpBFSO%r$&N+12JL=1=`it98Ef>sOxaTC@7* z=UZE2gLaDx6(??c-C?mSqIdDnfRoSuv<0i%2Y9n{c$vQa$HmCN@CAs856%!oaNZ5M zop;$mp!T`8+q6~&(?(7^Oiu- zVK3#HiMgf0}8#2G45G4bNDat}A$p%wQCEs5#Ihy;9F%l2AsH z(28l2y<$;i^|BVl{+{C%ayKf2h5Do|VVbc8_9J*8iR7ZY@x9w?28R zE{nk~`PRNmj%NGH{}wD(C^)o|)ql;37kiSdwkK3b$yj#^S8(gk{Qkp{YyJN4OFciN z-n~D#Z`m=Qom`yxhf^+38QlGcG zW76(@R=czF!>8W$?rE>~K5o*J@+-)c)&e`JsYjgZRCQynh|F=Svmx+PlF)O|lB>~T% zt`#MzMR|!i3L&684a%WsgHPuj0_M=~+G{kzr^tIuU|JFyqUz|mWR-f#oTY_^W}g-> z{rfA=ql4k#Mj`dv#+z5)m9*UA)ybtZv4nl%bQzrtPu7)!X7|2yPS_C4^JR_NEl;Ob z1+gAexy%CwXTML=maKfLnjZCa?x~)lnT;hAw=X<&fYVPZZ|Xj#=~1;zo5M3$LpGPK z{FY~L#A{xnyFijLJz?FFK&IncZt)&v4mokktaW!z%{kRyIaB0MMy*x(-&)aJ_8`pp z^f^8g7QO?&wC%1Gem^+Ba$;)Xz7HqFMfvVq?>gFcF!!U8-eaAWlQ&6y&A1o)GdghJ zvY)53CQduKNAJ}4ji=;us-H25#r#h0Hn8ZGVvFr6e`FF<$FXB#s=vUL(oVay1>0A$ zpPan)z_!Wvj-8z4ZRGtqv~SgmAFfRMyLFCd{jX1c@Bio7WpJ+k_o4ip9WY0KU`CDu zpBmIcQU(|Y`2{7J`FX|qIhlE-75boJH8~?OGY=dOzWsaonj8dLs^>l0r0SzVXhPT4ne?namErdvfqvY$%yL9G0~m&%luqfgo2ie+@`?v%4TazkK4)?gE}ssKIWHZBK|%sp=MhyvtHi(J7U_6`rbUT%EtFk-Osb8>0Lcjzx}*f zvFvk+X**;8v4N7`>vx_zHv&Dz4lU3ibqKoGWq~R@^GZ^4ax%RXJY8HJ72I?3lYogZ zIJE>+Q4|MwGcs{8;I4px`jG&vI$~rJVL((!$Ym?2LP7u)AQPeoqj~~ajBE&Uc0x6z z80bS}Ly!t(bVHES11RSqz)@fdff$0B50Om)1t4 Manage IDE settings > import settings...`; +> These tools are used to interface the IDE with the make scripts, and are necessary to use the run/debug configurations from CLion. +> They are stored globally, but you can easely delete them once they're not necesary anymore. + +## Files + +Contains: +- 2 configurations + - Run: to run a single test file (file in the `tests/` folder) selected in the editor, or all the tests when an implementation file is selected (or any file in the same folder as the `Makefile`) + - Debug Single test: when run in `Debug` mode, allows to use the integrated debugger of CLion to debug a test (opened and selected in the editor) diff --git a/ex/example11/.idea/customTargets.xml b/ex/example11/.idea/customTargets.xml new file mode 100644 index 0000000..7cfdaab --- /dev/null +++ b/ex/example11/.idea/customTargets.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ex/example11/.idea/misc.xml b/ex/example11/.idea/misc.xml new file mode 100644 index 0000000..53624c9 --- /dev/null +++ b/ex/example11/.idea/misc.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file diff --git a/ex/example11/.idea/runConfigurations/Debug_single_test.xml b/ex/example11/.idea/runConfigurations/Debug_single_test.xml new file mode 100644 index 0000000..9edcbcc --- /dev/null +++ b/ex/example11/.idea/runConfigurations/Debug_single_test.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/ex/example11/.idea/runConfigurations/Run.xml b/ex/example11/.idea/runConfigurations/Run.xml new file mode 100644 index 0000000..7a8b2ba --- /dev/null +++ b/ex/example11/.idea/runConfigurations/Run.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/ex/example11/.idea/tools/Basic Testing.xml b/ex/example11/.idea/tools/Basic Testing.xml new file mode 100644 index 0000000..2716789 --- /dev/null +++ b/ex/example11/.idea/tools/Basic Testing.xml @@ -0,0 +1,16 @@ + + + + + + + + + + \ No newline at end of file From a140cc35db80fc51c091eeaa3a8f73161479c6a3 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Fri, 19 Apr 2024 11:53:01 +0200 Subject: [PATCH 11/29] Moved config folders to use symlinks. minor changes to makefile targets - detect if terminal environment is available for coloring with tput - remove debgme executable on clean --- basic_testing.mk | 7 ++++++- ex/{example11 => }/.idea/.gitignore | 0 ex/{example11 => }/.idea/CLion-bt-tools.zip | Bin ex/{example11 => }/.idea/README.md | 0 ex/{example11 => }/.idea/customTargets.xml | 2 +- ex/{example11 => }/.idea/misc.xml | 0 .../.idea/runConfigurations/Debug_single_test.xml | 4 ++-- ex/{example11 => }/.idea/runConfigurations/Run.xml | 2 +- ex/{example11 => }/.idea/tools/Basic Testing.xml | 0 {.vscode => ex/.vscode}/launch.json | 0 {.vscode => ex/.vscode}/tasks.json | 0 ex/example11/.idea | 1 + ex/example11/.vscode | 1 + ex/example5/.idea | 1 + 14 files changed, 13 insertions(+), 5 deletions(-) rename ex/{example11 => }/.idea/.gitignore (100%) rename ex/{example11 => }/.idea/CLion-bt-tools.zip (100%) rename ex/{example11 => }/.idea/README.md (100%) rename ex/{example11 => }/.idea/customTargets.xml (89%) rename ex/{example11 => }/.idea/misc.xml (100%) rename ex/{example11 => }/.idea/runConfigurations/Debug_single_test.xml (83%) rename ex/{example11 => }/.idea/runConfigurations/Run.xml (81%) rename ex/{example11 => }/.idea/tools/Basic Testing.xml (100%) rename {.vscode => ex/.vscode}/launch.json (100%) rename {.vscode => ex/.vscode}/tasks.json (100%) create mode 120000 ex/example11/.idea create mode 120000 ex/example11/.vscode create mode 120000 ex/example5/.idea diff --git a/basic_testing.mk b/basic_testing.mk index f095f1f..bd5e409 100644 --- a/basic_testing.mk +++ b/basic_testing.mk @@ -49,7 +49,12 @@ SUPPRESS_DIAGNOSTICS=yes else SUPPRESS_DIAGNOSTICS= endif + TEST_COLORS=yes +# $TERM variable not always defined, but required by tput (Eg, CLion run console). +ifeq ($(TERM),) +TEST_COLORS=no +endif ifeq ($(TEST_COLORS),no) COLOR_RED := COLOR_GREEN := @@ -236,7 +241,7 @@ check-single-bin: $(BIN_NAME) .PHONY: clean clean: rm -f $(PROGRAMS) *-valgrind $(OBJECTS) tests/*.o $(TESTS_BIN) \ - *.gcov *.gcda *.gcno tests/*.gcov tests/*.gcda tests/*.gcno + tests/debugme *.gcov *.gcda *.gcno tests/*.gcov tests/*.gcda tests/*.gcno .PHONY: coverage coverage: diff --git a/ex/example11/.idea/.gitignore b/ex/.idea/.gitignore similarity index 100% rename from ex/example11/.idea/.gitignore rename to ex/.idea/.gitignore diff --git a/ex/example11/.idea/CLion-bt-tools.zip b/ex/.idea/CLion-bt-tools.zip similarity index 100% rename from ex/example11/.idea/CLion-bt-tools.zip rename to ex/.idea/CLion-bt-tools.zip diff --git a/ex/example11/.idea/README.md b/ex/.idea/README.md similarity index 100% rename from ex/example11/.idea/README.md rename to ex/.idea/README.md diff --git a/ex/example11/.idea/customTargets.xml b/ex/.idea/customTargets.xml similarity index 89% rename from ex/example11/.idea/customTargets.xml rename to ex/.idea/customTargets.xml index 7cfdaab..f8984c7 100644 --- a/ex/example11/.idea/customTargets.xml +++ b/ex/.idea/customTargets.xml @@ -4,7 +4,7 @@ - + diff --git a/ex/example11/.idea/misc.xml b/ex/.idea/misc.xml similarity index 100% rename from ex/example11/.idea/misc.xml rename to ex/.idea/misc.xml diff --git a/ex/example11/.idea/runConfigurations/Debug_single_test.xml b/ex/.idea/runConfigurations/Debug_single_test.xml similarity index 83% rename from ex/example11/.idea/runConfigurations/Debug_single_test.xml rename to ex/.idea/runConfigurations/Debug_single_test.xml index 9edcbcc..faa4e86 100644 --- a/ex/example11/.idea/runConfigurations/Debug_single_test.xml +++ b/ex/.idea/runConfigurations/Debug_single_test.xml @@ -1,8 +1,8 @@ - + - + \ No newline at end of file diff --git a/ex/example11/.idea/runConfigurations/Run.xml b/ex/.idea/runConfigurations/Run.xml similarity index 81% rename from ex/example11/.idea/runConfigurations/Run.xml rename to ex/.idea/runConfigurations/Run.xml index 7a8b2ba..dc53b91 100644 --- a/ex/example11/.idea/runConfigurations/Run.xml +++ b/ex/.idea/runConfigurations/Run.xml @@ -1,5 +1,5 @@ - + diff --git a/ex/example11/.idea/tools/Basic Testing.xml b/ex/.idea/tools/Basic Testing.xml similarity index 100% rename from ex/example11/.idea/tools/Basic Testing.xml rename to ex/.idea/tools/Basic Testing.xml diff --git a/.vscode/launch.json b/ex/.vscode/launch.json similarity index 100% rename from .vscode/launch.json rename to ex/.vscode/launch.json diff --git a/.vscode/tasks.json b/ex/.vscode/tasks.json similarity index 100% rename from .vscode/tasks.json rename to ex/.vscode/tasks.json diff --git a/ex/example11/.idea b/ex/example11/.idea new file mode 120000 index 0000000..a3f7d20 --- /dev/null +++ b/ex/example11/.idea @@ -0,0 +1 @@ +../.idea/ \ No newline at end of file diff --git a/ex/example11/.vscode b/ex/example11/.vscode new file mode 120000 index 0000000..7796dd0 --- /dev/null +++ b/ex/example11/.vscode @@ -0,0 +1 @@ +../.vscode/ \ No newline at end of file diff --git a/ex/example5/.idea b/ex/example5/.idea new file mode 120000 index 0000000..a3f7d20 --- /dev/null +++ b/ex/example5/.idea @@ -0,0 +1 @@ +../.idea/ \ No newline at end of file From f8b3f0d0d556f4065ae5659305e048a729e36775 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Mon, 13 May 2024 11:55:31 +0200 Subject: [PATCH 12/29] added todo --- TODO.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 TODO.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..141d79e --- /dev/null +++ b/TODO.md @@ -0,0 +1,7 @@ +# Todo (nick) + +- [x] Look if possible to invoke task from launch.json, and shows in button. +- > conclusion: Not possible to add button, or custom "Run" task: possible to just run it +- [x] Determine if file is implementation or test (in tests directory) +- [x] CLion debugging + From 2516880b9429d27d6d90aaa99f71912f6235bd23 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Mon, 13 May 2024 11:55:59 +0200 Subject: [PATCH 13/29] Updated todo 19.04.24 --- TODO.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/TODO.md b/TODO.md index 141d79e..22a2d87 100644 --- a/TODO.md +++ b/TODO.md @@ -5,3 +5,24 @@ - [x] Determine if file is implementation or test (in tests directory) - [x] CLion debugging +## 19.04 + +- [/] investigate files appearing when running run configurations +- [/] analyze problem of shell scripts (when/where interpreter is chosen) +- [/] look workings with shell/IO tests + +- If time, generate automatically tests + - ~ CLI to generate folder and file structure + - lookup Unity C + +-> Ideas: m4 to fill up boilerplate + ```m4 + include(bt.m4) // implicit + + Suite(name) // sets current suite/file to generate + Test_compile() + Test_alloc_ok(type) // type is the type declaration + + ``` +-> Nope + From 61cf6f158f2eaaae2eb290445920d1f8627fcec7 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Mon, 13 May 2024 15:55:28 +0200 Subject: [PATCH 14/29] Updated todo 26.04.24 --- TODO.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/TODO.md b/TODO.md index 22a2d87..f0c474a 100644 --- a/TODO.md +++ b/TODO.md @@ -26,3 +26,20 @@ ``` -> Nope +## 26.04 + +- [ ] look workings with shell/IO tests + - Run can just run everything + - Debug has to make choiches, so better to have a debug target handling it?: + - make debug file.ext + - > if ext == c; then compile, cp to debugme, and run it (ez, done); + > if ext == in | expected; then needs some input redirection (hard); + > if ext == sh; then needs to run the program as in the shell script?? (Hardest); +- [x] investigate files appearing when running run configurations + - ? touch only with `if [[ -f ... ]]; then touch ... fi;`? + - touch $fileName$ can create file in projectDir directory; + -> TODO: should all be from same dir as makefile, instead of projectDir? +- [ ] analyze problem of shell scripts (when/where interpreter is chosen) +- [x] VScode not showning tasks anymore (ex/example11) + -> .vscode or .idea folder must be in root of the project + From 1b7930b7bda6d1f935bb887804a0fce44bea136e Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Mon, 13 May 2024 15:56:02 +0200 Subject: [PATCH 15/29] Updated todo 10.05.24 --- TODO.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/TODO.md b/TODO.md index f0c474a..d9524c7 100644 --- a/TODO.md +++ b/TODO.md @@ -43,3 +43,45 @@ - [x] VScode not showning tasks anymore (ex/example11) -> .vscode or .idea folder must be in root of the project +## 10.05 + +- Will there ever be test sets with more than one of IO / sh / c-cxx? + - (y/n): (__**Kinda, shell could also be IO, but all confined in .sh file**__) + - Specific run configuration file for each type of set? + - makefile to make all decisions, based on `TESTS_(IO|SH|C|CXX)` variables? + +- Types + - Shell: Used to test/run binary implementation with specific arguments (e.g cli), (!?!)or other uses? + - I/O: Used to test/run binary implementation, with specific stdin, and expected output + - c/cpp src files: Used to test library implementations + +- Debugging problems: + - Library: None, just copy the test + - Binary programs: + - how to select the correct compiled binary, to copy into a file named `debugme`? + - Need to open src file anyway? + - Makefile script to choose when project is library, or test suite, so which compiled binary to copy. + - usually I/O or shell, so see below problems + - Shell: + - how to get the arguments present in the shell script, to pass to the binary? + - I/O: choose which .in file to run + - Manual prompt? + + +- Proposal: + - Common `Run all` configuration + - CLion: Run configuration (Button) + - VScode: Run task, instructions needed for keyboard shortcut + - Ctrl + Shift + B + - Specific debug configuration, for each test suite type (either) + - Library: currently open `test.c` or `test.cc` file + - IO: prompt to pickup file for stdin redirect + - Clion: either file, or name prompt + - VScode: can be configurable/generetable, by adding a specific field at the end of the file + +### TODO + +- [ ] Stabilize current solution + - [ ] Check which files are necessary to make everything work +- [ ] explore debugging for sh files +- [ ] ocmplete section 1 of report, start section 2 From 98dbfbfccfe49e6fdfdef8169ae98d697fbff78d Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Mon, 13 May 2024 16:45:47 +0200 Subject: [PATCH 16/29] Added VScode configuration for IO tests --- ex/.vscode/launch.json | 39 +++++++++++++++++++++++++++++++++++++-- ex/.vscode/tasks.json | 2 +- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/ex/.vscode/launch.json b/ex/.vscode/launch.json index 92e8ad9..1a617c0 100644 --- a/ex/.vscode/launch.json +++ b/ex/.vscode/launch.json @@ -5,7 +5,7 @@ "version": "0.2.0", "configurations": [ { - "name": "debug current test (gdb)", + "name": "debug library test (gdb/lldb)", // Requires C/C++ extension from Microsoft "type": "cppdbg", "request": "launch", @@ -28,7 +28,30 @@ } ], }, - + { + "name": "debug binary IO (gdb/lldb)", + // Requires C/C++ extension from Microsoft + "type": "cppdbg", + "request": "launch", + "cwd": "${fileDirname}", + "preLaunchTask": "Build and run tests", + "program": "${fileDirname}/${fileBasenameNoExtension}", + "args": ["-d", "<", "tests/${input:test}"], + // Requires C/C++ extension from Microsoft + "MIMode": "${input:debugger}", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + }, ], "inputs": [ { @@ -41,5 +64,17 @@ ], "default": "gdb" }, + { + "type": "pickString", + "id": "test", + "description": "Pick the input file to pass to the program", + // TODO: make it so it's generated at runtime, or on test generation! + "options": [ + "test0.in", + "test1.in", + "test2.in", + ], + "default": "gdb" + }, ], } diff --git a/ex/.vscode/tasks.json b/ex/.vscode/tasks.json index a7b8470..bc6e3f2 100644 --- a/ex/.vscode/tasks.json +++ b/ex/.vscode/tasks.json @@ -7,7 +7,7 @@ "detail": "Runs all tests, or a single test when opened in the editor", "type": "shell", "presentation": { - "reveal": "never" + "reveal": "always" }, "options": { "cwd": "${fileDirname}/", From 611668d91af5099ea320cca2dba0953a2cec446c Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Mon, 13 May 2024 16:46:33 +0200 Subject: [PATCH 17/29] Added CLion configuration for IO tests --- ex/.idea/runConfigurations/Debug_IO.xml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 ex/.idea/runConfigurations/Debug_IO.xml diff --git a/ex/.idea/runConfigurations/Debug_IO.xml b/ex/.idea/runConfigurations/Debug_IO.xml new file mode 100644 index 0000000..d2c56ce --- /dev/null +++ b/ex/.idea/runConfigurations/Debug_IO.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file From 51764ec4e56a74a4aae3568651b3f50f5b6c2444 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Mon, 13 May 2024 16:48:11 +0200 Subject: [PATCH 18/29] minor changes to CLion run and debug configurations --- ex/.idea/runConfigurations/Debug_single_test.xml | 4 ++-- ex/.idea/runConfigurations/Run.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ex/.idea/runConfigurations/Debug_single_test.xml b/ex/.idea/runConfigurations/Debug_single_test.xml index faa4e86..7bb19b2 100644 --- a/ex/.idea/runConfigurations/Debug_single_test.xml +++ b/ex/.idea/runConfigurations/Debug_single_test.xml @@ -1,8 +1,8 @@ - + - \ No newline at end of file + diff --git a/ex/.idea/runConfigurations/Run.xml b/ex/.idea/runConfigurations/Run.xml index dc53b91..5519db8 100644 --- a/ex/.idea/runConfigurations/Run.xml +++ b/ex/.idea/runConfigurations/Run.xml @@ -1,5 +1,5 @@ - + From c634b0dc5e262afb75e4b1449035d7c113f73662 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Fri, 17 May 2024 11:04:20 +0200 Subject: [PATCH 19/29] Added meeting notes --- TODO.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index d9524c7..c2d2696 100644 --- a/TODO.md +++ b/TODO.md @@ -82,6 +82,19 @@ ### TODO - [ ] Stabilize current solution - - [ ] Check which files are necessary to make everything work + - Check which files are necessary to make everything work + - check that current stuff works - [ ] explore debugging for sh files -- [ ] ocmplete section 1 of report, start section 2 +- [ ] complete section 1 of report, start section 2 + +## 17.05 + +- Linker: wrap (dll-library to substitute symbols) + - anche per test IO + - studente crea un main + - altro programma con "vero" main, va a chiamare main altro! + - linker:`--wrap = main` + - Take every undefined reference to symbol, and transform in symbol `__wrap_symbol_` + - => define wrapper + - IO: intercept stodut of program: more difficult + - New version: capture IO functions (mostly O), for pinpoint comparison! From 9ea4c17711488b8a9be8d7f8d16966d6fb898db3 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Fri, 24 May 2024 09:28:10 +0200 Subject: [PATCH 20/29] updated todos and added info for linker `--wrap` option --- TODO.md | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index c2d2696..38bf864 100644 --- a/TODO.md +++ b/TODO.md @@ -85,7 +85,7 @@ - Check which files are necessary to make everything work - check that current stuff works - [ ] explore debugging for sh files -- [ ] complete section 1 of report, start section 2 +- [x] complete section 1 of report, start section 2 ## 17.05 @@ -98,3 +98,51 @@ - => define wrapper - IO: intercept stodut of program: more difficult - New version: capture IO functions (mostly O), for pinpoint comparison! + From LD manual: +```txt --wrap=symbol +Use a wrapper function for symbol. Any undefined reference to +symbol will be resolved to "__wrap_symbol". Any undefined +reference to "__real_symbol" will be resolved to symbol. + +This can be used to provide a wrapper for a system function. The +wrapper function should be called "__wrap_symbol". If it wishes to +call the system function, it should call "__real_symbol". + +Here is a trivial example: + + void * + __wrap_malloc (size_t c) + { + printf ("malloc called with %zu\n", c); + return __real_malloc (c); + } + +If you link other code with this file using --wrap malloc, then all +calls to "malloc" will call the function "__wrap_malloc" instead. +The call to "__real_malloc" in "__wrap_malloc" will call the real +"malloc" function. + +You may wish to provide a "__real_malloc" function as well, so that +links without the --wrap option will succeed. If you do this, you +should not put the definition of "__real_malloc" in the same file +as "__wrap_malloc"; if you do, the assembler may resolve the call +before the linker has a chance to wrap it to "malloc". + +Only undefined references are replaced by the linker. So, +translation unit internal references to symbol are not resolved to +"__wrap_symbol". In the next example, the call to "f" in "g" is +not resolved to "__wrap_f". + + int + f (void) + { + return 123; + } + + int + g (void) + { + return f(); + } +``` +Order of compilation may matter. From 5c3c9fe46862afb6d29cbbfe396b78c455330432 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Fri, 24 May 2024 09:28:25 +0200 Subject: [PATCH 21/29] minor changes to readme --- ex/.idea/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ex/.idea/README.md b/ex/.idea/README.md index c61167d..45ac025 100644 --- a/ex/.idea/README.md +++ b/ex/.idea/README.md @@ -10,5 +10,6 @@ Contains: - 2 configurations - - Run: to run a single test file (file in the `tests/` folder) selected in the editor, or all the tests when an implementation file is selected (or any file in the same folder as the `Makefile`) - - Debug Single test: when run in `Debug` mode, allows to use the integrated debugger of CLion to debug a test (opened and selected in the editor) + - `Run`: to run a single test file (file in the `tests/` folder) selected in the editor, or all the tests when an implementation file is selected (or any file in the same folder as the `Makefile`) + - `Debug Single test`: when run in `Debug` mode, allows to use the integrated debugger of CLion to debug a test (opened and selected in the editor) + - `Debug IO`: when run in `Debug` mode, allows to debug the IO tests (with `test.in` and `test.out` files) From f09be58e8a93e52ed3ed2748af51d855f4b491ba Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Sun, 26 May 2024 11:34:16 +0200 Subject: [PATCH 22/29] Working I/O main wrap draft --- Makefile | 2 +- basic_testing.mk | 2 +- ex/main-wrap/Makefile | 8 ++++++ ex/main-wrap/diamond.c | 26 +++++++++++++++++ ex/main-wrap/tests/test0.c | 7 +++++ ex/main-wrap/tests/test0.expected | 0 ex/main-wrap/tests/test4.c | 47 +++++++++++++++++++++++++++++++ ex/main-wrap/tests/test4.expected | 19 +++++++++++++ 8 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 ex/main-wrap/Makefile create mode 100644 ex/main-wrap/diamond.c create mode 100644 ex/main-wrap/tests/test0.c create mode 100644 ex/main-wrap/tests/test0.expected create mode 100644 ex/main-wrap/tests/test4.c create mode 100644 ex/main-wrap/tests/test4.expected diff --git a/Makefile b/Makefile index 610acd4..28fc450 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ all: all-examples EXAMPLES = ex/example1 ex/example2 ex/example3 ex/example4 \ - ex/example5 ex/example6 ex/example7 ex/example8 ex/example11 \ + ex/example5 ex/example6 ex/example7 ex/example8 ex/example11 ex/main-wrap \ 'ex ws/example1 ws' 'ex ws/example2 ws' 'ex ws/example3 ws' 'ex ws/example4 ws' \ 'ex ws/example5 ws' 'ex ws/example6 ws' 'ex ws/example7 ws' 'ex ws/example8 ws' diff --git a/basic_testing.mk b/basic_testing.mk index bd5e409..21c42d8 100644 --- a/basic_testing.mk +++ b/basic_testing.mk @@ -241,7 +241,7 @@ check-single-bin: $(BIN_NAME) .PHONY: clean clean: rm -f $(PROGRAMS) *-valgrind $(OBJECTS) tests/*.o $(TESTS_BIN) \ - tests/debugme *.gcov *.gcda *.gcno tests/*.gcov tests/*.gcda tests/*.gcno + tests/debugme *.gcov *.gcda *.gcno tests/*.gcov tests/*.gcda tests/*.gcno tests/*.out .PHONY: coverage coverage: diff --git a/ex/main-wrap/Makefile b/ex/main-wrap/Makefile new file mode 100644 index 0000000..21270f5 --- /dev/null +++ b/ex/main-wrap/Makefile @@ -0,0 +1,8 @@ +# PROGRAMS = diamond # we need to treat the binary file as an object, to be able to link on it with the --wrap option +OBJECTS=diamond.o +LDFLAGS=-Wl,--wrap=main + +TESTS_IO:=$(wildcard $(TESTS_DIR)/*.in) +TESTS_IO_NAMES:=$(sort $(patsubst $(TESTS_DIR)/%.in, %, $(TESTS_IO))) + +include ../../basic_testing.mk diff --git a/ex/main-wrap/diamond.c b/ex/main-wrap/diamond.c new file mode 100644 index 0000000..b87dbb6 --- /dev/null +++ b/ex/main-wrap/diamond.c @@ -0,0 +1,26 @@ +#include +#include + +void print_diamond(int n) { + for (int i = 1; i <= n; ++i) { + for (int j = n - i; j > 0; --j) + putchar(' '); + for (int j = 1; j < 2*i; ++j) + putchar('#'); + putchar('\n'); + } + for (int i = n-1; i >= 1; --i) { + for (int j = n - i; j > 0; --j) + putchar(' '); + for (int j = 1; j < 2*i; ++j) + putchar('#'); + putchar('\n'); + } +} + +int main(int argc, char * argv[]) { + int n = 10; + if (argc > 1) + n = atoi(argv[1]); + print_diamond(n); +} diff --git a/ex/main-wrap/tests/test0.c b/ex/main-wrap/tests/test0.c new file mode 100644 index 0000000..43a7195 --- /dev/null +++ b/ex/main-wrap/tests/test0.c @@ -0,0 +1,7 @@ +extern int __real_main(int, char*[]); + +int __wrap_main() { + char* argv[] = {"diamond", "0"}; + int result = __real_main(2, argv); + return result; +} diff --git a/ex/main-wrap/tests/test0.expected b/ex/main-wrap/tests/test0.expected new file mode 100644 index 0000000..e69de29 diff --git a/ex/main-wrap/tests/test4.c b/ex/main-wrap/tests/test4.c new file mode 100644 index 0000000..c6eab0a --- /dev/null +++ b/ex/main-wrap/tests/test4.c @@ -0,0 +1,47 @@ +extern int __real_main(int, char*[]); +#include +#include + +int __wrap_main() { + // Generate filenames + // TODO: find good buffer size + char* basefilename = __FILE__; + char outfilename[128] = {0}; + char exfilename[128] = {0}; + strncat(outfilename, basefilename, strlen(basefilename)-1); + strncat(exfilename, basefilename, strlen(basefilename)-1); + strcat(outfilename, "out"); + strcat(exfilename, "expected"); + + // redirect stdout to file + FILE *outfile; + if ((outfile = freopen(outfilename, "w", stdout)) == NULL) { + perror("freopen() failed"); + return 1; + } + int result = __real_main(2, (char*[]) {"diamond", "10"}); + fclose(outfile); + + // compare outputs, char by char + // TODO: check that everything works! + outfile = fopen(outfilename, "r"); + FILE * exfile = fopen(exfilename, "r"); + int out_ch, ex_ch, row, column = 0; + for(int i=0; + (out_ch = fgetc(outfile)) != EOF + && (ex_ch = fgetc(exfile)) != EOF; + ++i) { + if (out_ch != ex_ch) { + fprintf(stderr, "Output char \"%c\" different from expected char \"%c\"\n%s:%d:%d\ncheck respective I/O files for differences\n", + out_ch, ex_ch, outfilename,row, column); + return 1; + } + ++column; + if (out_ch == '\n') { + ++row; + column = 0; + } + } + remove(outfilename); + return result; +} diff --git a/ex/main-wrap/tests/test4.expected b/ex/main-wrap/tests/test4.expected new file mode 100644 index 0000000..a70af5d --- /dev/null +++ b/ex/main-wrap/tests/test4.expected @@ -0,0 +1,19 @@ + # + ### + ##### + ####### + ######### + ########### + ############# + ############### + ################# +################### + ################# + ############### + ############# + ########### + ######### + ####### + ##### + ### + # From 5798cf5b8730fcdbae2e1d37f85f2de5eb7b3e11 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Sun, 26 May 2024 18:39:24 +0200 Subject: [PATCH 23/29] minor resource cleanup fix --- ex/main-wrap/tests/test4.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ex/main-wrap/tests/test4.c b/ex/main-wrap/tests/test4.c index c6eab0a..0a9cb90 100644 --- a/ex/main-wrap/tests/test4.c +++ b/ex/main-wrap/tests/test4.c @@ -22,10 +22,17 @@ int __wrap_main() { int result = __real_main(2, (char*[]) {"diamond", "10"}); fclose(outfile); - // compare outputs, char by char + // load files and compare outputs, char by char // TODO: check that everything works! - outfile = fopen(outfilename, "r"); + if ((outfile = fopen(outfilename, "r")) == NULL) { + fprintf(stderr, "Failed to open file %s\n", outfilename); + return 1; + } FILE * exfile = fopen(exfilename, "r"); + if (exfile == NULL) { + fprintf(stderr, "Failed to open file %s\n", exfilename); + return 1; + } int out_ch, ex_ch, row, column = 0; for(int i=0; (out_ch = fgetc(outfile)) != EOF @@ -34,6 +41,8 @@ int __wrap_main() { if (out_ch != ex_ch) { fprintf(stderr, "Output char \"%c\" different from expected char \"%c\"\n%s:%d:%d\ncheck respective I/O files for differences\n", out_ch, ex_ch, outfilename,row, column); + fclose(outfile); + fclose(exfile); return 1; } ++column; @@ -43,5 +52,7 @@ int __wrap_main() { } } remove(outfilename); + fclose(outfile); + fclose(exfile); return result; } From df70d5cee43d124678e351d6d4e29864bbf32af5 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Sun, 26 May 2024 22:34:56 +0200 Subject: [PATCH 24/29] example code for stdin redirection --- ex/main-wrap/tests/test4.c | 14 ++++++++++++++ ex/main-wrap/tests/test4.in | 1 + 2 files changed, 15 insertions(+) create mode 100644 ex/main-wrap/tests/test4.in diff --git a/ex/main-wrap/tests/test4.c b/ex/main-wrap/tests/test4.c index 0a9cb90..efa73a5 100644 --- a/ex/main-wrap/tests/test4.c +++ b/ex/main-wrap/tests/test4.c @@ -6,13 +6,27 @@ int __wrap_main() { // Generate filenames // TODO: find good buffer size char* basefilename = __FILE__; + char infilename[128] = {0}; char outfilename[128] = {0}; char exfilename[128] = {0}; + strncat(infilename, basefilename, strlen(basefilename)-1); strncat(outfilename, basefilename, strlen(basefilename)-1); strncat(exfilename, basefilename, strlen(basefilename)-1); + strcat(infilename, "in"); strcat(outfilename, "out"); strcat(exfilename, "expected"); + if (freopen(infilename, "r", stdin) == NULL) { + // TODO: check that error is no file, can ignore then, other + perror("freopen() for stdin failed"); + } + + // Temporary test to showcase stdin redirection (from file) + int ch; + while((ch=getchar()) != EOF) { + putchar(ch); + } + // redirect stdout to file FILE *outfile; if ((outfile = freopen(outfilename, "w", stdout)) == NULL) { diff --git a/ex/main-wrap/tests/test4.in b/ex/main-wrap/tests/test4.in new file mode 100644 index 0000000..3045e4e --- /dev/null +++ b/ex/main-wrap/tests/test4.in @@ -0,0 +1 @@ +HEllo world, from redirected stdin! From b24752a7db90a777efcac8d2902e3814694feca1 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Mon, 27 May 2024 08:28:55 +0200 Subject: [PATCH 25/29] refactored filename generation --- ex/main-wrap/tests/test4.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/ex/main-wrap/tests/test4.c b/ex/main-wrap/tests/test4.c index efa73a5..26957b3 100644 --- a/ex/main-wrap/tests/test4.c +++ b/ex/main-wrap/tests/test4.c @@ -2,21 +2,19 @@ extern int __real_main(int, char*[]); #include #include +#define filename(ext) \ + char ext##_filename[128] = {0}; \ + strncat( ext##_filename, __FILE__, strlen(__FILE__)-1); \ + strcat(ext##_filename, #ext) + int __wrap_main() { // Generate filenames // TODO: find good buffer size - char* basefilename = __FILE__; - char infilename[128] = {0}; - char outfilename[128] = {0}; - char exfilename[128] = {0}; - strncat(infilename, basefilename, strlen(basefilename)-1); - strncat(outfilename, basefilename, strlen(basefilename)-1); - strncat(exfilename, basefilename, strlen(basefilename)-1); - strcat(infilename, "in"); - strcat(outfilename, "out"); - strcat(exfilename, "expected"); + filename(in); + filename(out); + filename(expected); - if (freopen(infilename, "r", stdin) == NULL) { + if (freopen(in_filename, "r", stdin) == NULL) { // TODO: check that error is no file, can ignore then, other perror("freopen() for stdin failed"); } @@ -29,7 +27,7 @@ int __wrap_main() { // redirect stdout to file FILE *outfile; - if ((outfile = freopen(outfilename, "w", stdout)) == NULL) { + if ((outfile = freopen(out_filename, "w", stdout)) == NULL) { perror("freopen() failed"); return 1; } @@ -38,13 +36,13 @@ int __wrap_main() { // load files and compare outputs, char by char // TODO: check that everything works! - if ((outfile = fopen(outfilename, "r")) == NULL) { - fprintf(stderr, "Failed to open file %s\n", outfilename); + if ((outfile = fopen(out_filename, "r")) == NULL) { + fprintf(stderr, "Failed to open file %s\n", out_filename); return 1; } - FILE * exfile = fopen(exfilename, "r"); + FILE * exfile = fopen(expected_filename, "r"); if (exfile == NULL) { - fprintf(stderr, "Failed to open file %s\n", exfilename); + fprintf(stderr, "Failed to open file %s\n", expected_filename); return 1; } int out_ch, ex_ch, row, column = 0; @@ -54,7 +52,7 @@ int __wrap_main() { ++i) { if (out_ch != ex_ch) { fprintf(stderr, "Output char \"%c\" different from expected char \"%c\"\n%s:%d:%d\ncheck respective I/O files for differences\n", - out_ch, ex_ch, outfilename,row, column); + out_ch, ex_ch, out_filename,row, column); fclose(outfile); fclose(exfile); return 1; @@ -65,7 +63,7 @@ int __wrap_main() { column = 0; } } - remove(outfilename); + remove(out_filename); fclose(outfile); fclose(exfile); return result; From 185e37fe864e43740269b4ce5cbe38588017bc7d Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Mon, 27 May 2024 14:58:43 +0200 Subject: [PATCH 26/29] refactored IO tests into single test driver --- basic_testing.h | 35 ++++++++++++++++++ ex/example11.expected | 2 +- ex/main-wrap/tests/test4.c | 73 +++----------------------------------- 3 files changed, 41 insertions(+), 69 deletions(-) diff --git a/basic_testing.h b/basic_testing.h index 92b0437..ba30ca8 100644 --- a/basic_testing.h +++ b/basic_testing.h @@ -448,4 +448,39 @@ int bt_test_driver(int argc, char * argv[]) { } #endif +// IO tests macros +#define FILENAME(ext) \ + char ext##_filename[128] = {0}; \ + strncat(ext##_filename, __FILE__, strlen(__FILE__)-1); \ + strcat(ext##_filename, #ext) + +struct bt_io_test_data { + FILE* out_file; + FILE* expected_file; +}; + +#define VALIDATE int bt_io_validate(struct bt_io_test_data data) + +#define RUN_PROGRAM(...) \ + extern int __real_main(int, char*[]); \ + int __wrap_main() { \ + FILENAME(in); \ + FILENAME(out); \ + FILENAME(expected); \ + BT_POSSIBLY_UNUSED FILE* in_file = freopen(in_filename, "r", stdin); \ + BT_POSSIBLY_UNUSED FILE* out_file = freopen(out_filename, "w", stdout); \ + int result = __real_main(2, (char*[]) { __VA_ARGS__ }); \ + if (in_file != NULL) fclose(in_file); \ + fclose(out_file); \ + if (result != 0) { \ + fprintf(stderr, "Implementation exited with value: %d", result);} \ + struct bt_io_test_data test_data = {\ + fopen(out_filename, "r"), \ + fopen(expected_filename, "r")}; \ + result = bt_io_validate(test_data); \ + fclose(test_data.out_file); \ + fclose(test_data.expected_file); \ + return !(result == BT_SUCCESS); \ + } + #endif /* BASIC_TESTING_H_INCLUDED */ diff --git a/ex/example11.expected b/ex/example11.expected index f66c147..2787976 100644 --- a/ex/example11.expected +++ b/ex/example11.expected @@ -1,2 +1,2 @@ Running test test0... PASS -Running test test1... PASS \ No newline at end of file +Running test test4... PASS diff --git a/ex/main-wrap/tests/test4.c b/ex/main-wrap/tests/test4.c index 26957b3..958e1a7 100644 --- a/ex/main-wrap/tests/test4.c +++ b/ex/main-wrap/tests/test4.c @@ -1,70 +1,7 @@ -extern int __real_main(int, char*[]); -#include -#include +#include "basic_testing.h" -#define filename(ext) \ - char ext##_filename[128] = {0}; \ - strncat( ext##_filename, __FILE__, strlen(__FILE__)-1); \ - strcat(ext##_filename, #ext) - -int __wrap_main() { - // Generate filenames - // TODO: find good buffer size - filename(in); - filename(out); - filename(expected); - - if (freopen(in_filename, "r", stdin) == NULL) { - // TODO: check that error is no file, can ignore then, other - perror("freopen() for stdin failed"); - } - - // Temporary test to showcase stdin redirection (from file) - int ch; - while((ch=getchar()) != EOF) { - putchar(ch); - } - - // redirect stdout to file - FILE *outfile; - if ((outfile = freopen(out_filename, "w", stdout)) == NULL) { - perror("freopen() failed"); - return 1; - } - int result = __real_main(2, (char*[]) {"diamond", "10"}); - fclose(outfile); - - // load files and compare outputs, char by char - // TODO: check that everything works! - if ((outfile = fopen(out_filename, "r")) == NULL) { - fprintf(stderr, "Failed to open file %s\n", out_filename); - return 1; - } - FILE * exfile = fopen(expected_filename, "r"); - if (exfile == NULL) { - fprintf(stderr, "Failed to open file %s\n", expected_filename); - return 1; - } - int out_ch, ex_ch, row, column = 0; - for(int i=0; - (out_ch = fgetc(outfile)) != EOF - && (ex_ch = fgetc(exfile)) != EOF; - ++i) { - if (out_ch != ex_ch) { - fprintf(stderr, "Output char \"%c\" different from expected char \"%c\"\n%s:%d:%d\ncheck respective I/O files for differences\n", - out_ch, ex_ch, out_filename,row, column); - fclose(outfile); - fclose(exfile); - return 1; - } - ++column; - if (out_ch == '\n') { - ++row; - column = 0; - } - } - remove(out_filename); - fclose(outfile); - fclose(exfile); - return result; +VALIDATE { + return BT_SUCCESS; } + +RUN_PROGRAM("diamond", "10"); From 471d8f2be582a506c32ddfd4f95734b0753d7ba7 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Wed, 29 May 2024 14:10:35 +0200 Subject: [PATCH 27/29] fixed mistake --- ex/example11.expected | 4 +++- ex/main-wrap.expected | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 ex/main-wrap.expected diff --git a/ex/example11.expected b/ex/example11.expected index 2787976..3e54e16 100644 --- a/ex/example11.expected +++ b/ex/example11.expected @@ -1,2 +1,4 @@ +Running test fail... FAIL Running test test0... PASS -Running test test4... PASS +Running test test1... PASS +Running test timeout... FAIL diff --git a/ex/main-wrap.expected b/ex/main-wrap.expected new file mode 100644 index 0000000..2787976 --- /dev/null +++ b/ex/main-wrap.expected @@ -0,0 +1,2 @@ +Running test test0... PASS +Running test test4... PASS From 572d9e9ea95e5ac67a50129a1615d50a72e7295b Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Sun, 2 Jun 2024 16:21:07 +0200 Subject: [PATCH 28/29] Removed validation function Added validation for 'hybrid' tests (C implementation and test files, with `.expected` files) in Makefile. --- basic_testing.h | 15 +-------------- basic_testing.mk | 16 ++++++++++++---- ex/main-wrap/tests/test0.c | 9 +++------ ex/main-wrap/tests/test4.c | 4 ---- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/basic_testing.h b/basic_testing.h index ba30ca8..85c4b03 100644 --- a/basic_testing.h +++ b/basic_testing.h @@ -454,13 +454,6 @@ int bt_test_driver(int argc, char * argv[]) { strncat(ext##_filename, __FILE__, strlen(__FILE__)-1); \ strcat(ext##_filename, #ext) -struct bt_io_test_data { - FILE* out_file; - FILE* expected_file; -}; - -#define VALIDATE int bt_io_validate(struct bt_io_test_data data) - #define RUN_PROGRAM(...) \ extern int __real_main(int, char*[]); \ int __wrap_main() { \ @@ -474,13 +467,7 @@ struct bt_io_test_data { fclose(out_file); \ if (result != 0) { \ fprintf(stderr, "Implementation exited with value: %d", result);} \ - struct bt_io_test_data test_data = {\ - fopen(out_filename, "r"), \ - fopen(expected_filename, "r")}; \ - result = bt_io_validate(test_data); \ - fclose(test_data.out_file); \ - fclose(test_data.expected_file); \ - return !(result == BT_SUCCESS); \ + return result; \ } #endif /* BASIC_TESTING_H_INCLUDED */ diff --git a/basic_testing.mk b/basic_testing.mk index 21c42d8..2c772fd 100644 --- a/basic_testing.mk +++ b/basic_testing.mk @@ -21,6 +21,8 @@ TESTS_BIN:=$(patsubst $(TESTS_DIR)/%.c, $(TESTS_DIR)/%, $(TESTS_C)) \ $(patsubst $(TESTS_DIR)/%.cc, $(TESTS_DIR)/%, $(TESTS_CXX)) TESTS_BIN_NAMES:=$(sort $(patsubst $(TESTS_DIR)/%.c, %, $(TESTS_C)) $(patsubst $(TESTS_DIR)/%.cc, %, $(TESTS_CXX))) +TESTS_HYBRID:=$(wildcard $(TESTS_DIR)/*.expected) + .PHONY: all all: compile check @@ -176,7 +178,7 @@ check-io-sh: compile $(TESTS_IO) $(TESTS_SH) $(PROGRAMS_DRIVERS) else \ test_ko FAIL ;\ test_diag "see $(TESTS_DIR)/$$t.sh" ;\ - test_diag "run diff $$t.out $(TESTS_DIR)/$$t.expected";\ + test_diag "run diff -c $$t.out $(TESTS_DIR)/$$t.expected";\ test_diag "to see the difference between the actual and expected output";\ fi; \ fi; \ @@ -204,11 +206,17 @@ check-bin: $(TESTS_BIN) "$(TESTS_DIR)/$$t" -q &\ fi; \ $(SCRIPT_GET_TEST_RESULT); \ - if test $$res = KO; then \ - test_diag "run '$(TESTS_DIR)/$$t' to see what went wrong" ; \ + if test $$res = KO || test "$(TESTS_HYBRID)" != "" && ! cmp -s "$(TESTS_DIR)/$$t.out" "$(TESTS_DIR)/$$t.expected"; then \ + if test "$(TESTS_HYBRID)" != ""; then \ + test_ko FAIL ; \ + test_diag "run 'diff -c $(TESTS_DIR)/$$t.out $(TESTS_DIR)/$$t.expected' to see the mistakes"; \ + else \ + test_diag "run '$(TESTS_DIR)/$$t' to see what went wrong"; \ + fi; \ test_diag "run '$(TESTS_DIR)/$$t -d' with a debugger" ; \ else \ test_ok PASS; \ + if test ! -z $$TESTS_HYBRID; then rm -f "$(TESTS_DIR)/$$t.out"; fi; \ fi; \ done; \ test_summary 'Summary: PASS ' @@ -218,7 +226,7 @@ check-single-bin: $(BIN_NAME) @exec 2> /dev/null; \ if test -z $$BIN_NAME; then \ echo "Error: Missing test to run, please set BIN_NAME="; \ - echo " example: \`make check-single-bin BIN_NAME=tests/test0\`"; \ + echo " example: \'make check-single-bin BIN_NAME=tests/test0\'"; \ exit 1; fi; \ $(SCRIPT_INIT); \ t=$$BIN_NAME; \ diff --git a/ex/main-wrap/tests/test0.c b/ex/main-wrap/tests/test0.c index 43a7195..a10e123 100644 --- a/ex/main-wrap/tests/test0.c +++ b/ex/main-wrap/tests/test0.c @@ -1,7 +1,4 @@ -extern int __real_main(int, char*[]); +#include "basic_testing.h" + +RUN_PROGRAM("diamond", "0"); -int __wrap_main() { - char* argv[] = {"diamond", "0"}; - int result = __real_main(2, argv); - return result; -} diff --git a/ex/main-wrap/tests/test4.c b/ex/main-wrap/tests/test4.c index 958e1a7..6925789 100644 --- a/ex/main-wrap/tests/test4.c +++ b/ex/main-wrap/tests/test4.c @@ -1,7 +1,3 @@ #include "basic_testing.h" -VALIDATE { - return BT_SUCCESS; -} - RUN_PROGRAM("diamond", "10"); From 00303e03586a61cd0e94e1a7e15d850e9474d0d4 Mon Sep 17 00:00:00 2001 From: Nick Mazzu Date: Wed, 26 Jun 2024 12:29:04 +0200 Subject: [PATCH 29/29] minor changes + better documentation --- ex/.idea/README.md | 8 +++++--- ex/.idea/runConfigurations/Debug_IO.xml | 2 +- ex/.idea/runConfigurations/Debug_single_test.xml | 4 ++-- ex/.idea/runConfigurations/Run.xml | 2 +- ex/.vscode/README.md | 14 ++++++++++++++ ex/.vscode/launch.json | 6 +++++- ex/.vscode/tasks.json | 6 +++++- ex/main-wrap/Makefile | 1 + 8 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 ex/.vscode/README.md diff --git a/ex/.idea/README.md b/ex/.idea/README.md index 45ac025..d9b337a 100644 --- a/ex/.idea/README.md +++ b/ex/.idea/README.md @@ -4,12 +4,14 @@ - Import the external tools from the `CLion-bt-tools.zip` into your IDE, from `File > Manage IDE settings > import settings...`; > These tools are used to interface the IDE with the make scripts, and are necessary to use the run/debug configurations from CLion. -> They are stored globally, but you can easely delete them once they're not necesary anymore. +> They are stored globally, but you can easely delete them once they're not needed anymore. +- ensure that the `.idea` folder is located in the root of the exercise, and the folder of the exercise is the only one opened. ## Files Contains: -- 2 configurations +- 3 configurations - `Run`: to run a single test file (file in the `tests/` folder) selected in the editor, or all the tests when an implementation file is selected (or any file in the same folder as the `Makefile`) - - `Debug Single test`: when run in `Debug` mode, allows to use the integrated debugger of CLion to debug a test (opened and selected in the editor) + - `Debug Single test`: when run in `Debug` mode, allows to use the integrated debugger of CLion to debug a C or C++ test (opened and selected in the editor) - `Debug IO`: when run in `Debug` mode, allows to debug the IO tests (with `test.in` and `test.out` files) +- `CLion-bt-tools.zip`: Tools folder to import tests diff --git a/ex/.idea/runConfigurations/Debug_IO.xml b/ex/.idea/runConfigurations/Debug_IO.xml index d2c56ce..bc31ad5 100644 --- a/ex/.idea/runConfigurations/Debug_IO.xml +++ b/ex/.idea/runConfigurations/Debug_IO.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/ex/.idea/runConfigurations/Run.xml b/ex/.idea/runConfigurations/Run.xml index 5519db8..10969af 100644 --- a/ex/.idea/runConfigurations/Run.xml +++ b/ex/.idea/runConfigurations/Run.xml @@ -1,5 +1,5 @@ - + diff --git a/ex/.vscode/README.md b/ex/.vscode/README.md new file mode 100644 index 0000000..2c9804d --- /dev/null +++ b/ex/.vscode/README.md @@ -0,0 +1,14 @@ +# Basic testing VScode config + +## Setup + +- ensure that the `.vscode` folder is located in the root of the project opened in VScode; this can either be the folder of the single exercise, or a folder containing all other exercise's folders. + +## Files + +Contains 2 json files: +- `tasks.json`: build and run tasks, to run either all tests, or a single one (C test file opened in the editor). + - Ctrl + Shift + B, to run default build + - Ctrl + P to open command panel, type "task " to show all tasks +- `launch.json`: debug binary tests or implementation, and I/O tests (name of input file selectable from the dropdown). + - Ctrl + Shift + D to open Debug panel diff --git a/ex/.vscode/launch.json b/ex/.vscode/launch.json index 1a617c0..797b772 100644 --- a/ex/.vscode/launch.json +++ b/ex/.vscode/launch.json @@ -15,6 +15,8 @@ "args": ["-d"], // Requires C/C++ extension from Microsoft "MIMode": "${input:debugger}", + // "MIMode": "gdb", + // "MIMode": "lldb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", @@ -39,6 +41,8 @@ "args": ["-d", "<", "tests/${input:test}"], // Requires C/C++ extension from Microsoft "MIMode": "${input:debugger}", + // "MIMode": "gdb", + // "MIMode": "lldb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", @@ -74,7 +78,7 @@ "test1.in", "test2.in", ], - "default": "gdb" + "default": "test0.in" }, ], } diff --git a/ex/.vscode/tasks.json b/ex/.vscode/tasks.json index bc6e3f2..caa354f 100644 --- a/ex/.vscode/tasks.json +++ b/ex/.vscode/tasks.json @@ -63,7 +63,11 @@ "kind": "file" }, } - ] + ], + "group": { + "kind": "test", + "isDefault": true + } } ] diff --git a/ex/main-wrap/Makefile b/ex/main-wrap/Makefile index 21270f5..7b1d7c9 100644 --- a/ex/main-wrap/Makefile +++ b/ex/main-wrap/Makefile @@ -2,6 +2,7 @@ OBJECTS=diamond.o LDFLAGS=-Wl,--wrap=main +# TODO: check if it's still required! TESTS_IO:=$(wildcard $(TESTS_DIR)/*.in) TESTS_IO_NAMES:=$(sort $(patsubst $(TESTS_DIR)/%.in, %, $(TESTS_IO)))