From f25aa052cd31cab4c6301cca5eb8e5e5f129d5bd Mon Sep 17 00:00:00 2001 From: Pavel Boldin Date: Wed, 7 Feb 2018 23:59:39 +0200 Subject: [PATCH 15/89] add `fail to unpatch` test Add a test sample where patch is always busy in the loop and cannot be unapplied. Signed-off-by: Pavel Boldin --- tests/fail_unpatch/Makefile | 4 ++++ tests/fail_unpatch/desc | 1 + tests/fail_unpatch/fail_unpatch.c | 29 ++++++++++++++++++++++++++++ tests/fail_unpatch/fail_unpatch.diff | 11 +++++++++++ tests/run_tests.sh | 25 ++++++++++++++++++++++-- 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 tests/fail_unpatch/Makefile create mode 100644 tests/fail_unpatch/desc create mode 100644 tests/fail_unpatch/fail_unpatch.c create mode 100644 tests/fail_unpatch/fail_unpatch.diff diff --git a/tests/fail_unpatch/Makefile b/tests/fail_unpatch/Makefile new file mode 100644 index 0000000..d7680e9 --- /dev/null +++ b/tests/fail_unpatch/Makefile @@ -0,0 +1,4 @@ + +LDLIBS:=-lpthread + +include ../makefile.inc diff --git a/tests/fail_unpatch/desc b/tests/fail_unpatch/desc new file mode 100644 index 0000000..02151c5 --- /dev/null +++ b/tests/fail_unpatch/desc @@ -0,0 +1 @@ +fails to unpatch the code diff --git a/tests/fail_unpatch/fail_unpatch.c b/tests/fail_unpatch/fail_unpatch.c new file mode 100644 index 0000000..6b5c50f --- /dev/null +++ b/tests/fail_unpatch/fail_unpatch.c @@ -0,0 +1,29 @@ +#include +#include + +void print_greetings_patched(void) +{ + while (1) { + printf("Hello. This a PATCHED version!\n"); + sleep(1); + } +} + +void print_greetings(void) +{ + printf("Hello. This is an UNPATCHED version!\n"); +} + +void do_work() { + while (1) { + print_greetings(); + sleep(1); + } +} + +int main() +{ + do_work(); + + return 0; +} diff --git a/tests/fail_unpatch/fail_unpatch.diff b/tests/fail_unpatch/fail_unpatch.diff new file mode 100644 index 0000000..49738bd --- /dev/null +++ b/tests/fail_unpatch/fail_unpatch.diff @@ -0,0 +1,11 @@ +--- ./fail_unpatch.c 2018-02-07 18:39:27.145493215 +0200 ++++ ./fail_unpatch.c 2018-02-07 18:39:43.349482218 +0200 +@@ -11,7 +11,7 @@ + + void print_greetings(void) + { +- printf("Hello. This is an UNPATCHED version!\n"); ++ print_greetings_patched(); + } + + void do_work() { diff --git a/tests/run_tests.sh b/tests/run_tests.sh index fbfb273..2bdd303 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -105,6 +105,10 @@ check_result() { ! grep_tail 'UNPATCHED' return $? ;; + fail_unpatch) + grep_tail '\${outfile}_patched + cat ${outfile}_patched + echo "============unpatching===============" >>$logfile libcare_ctl unpatch-user -p $pid \ - >$logfile 2>&1 || : + >>$logfile 2>&1 || : sleep 2 -- 2.23.0