From 5500f8645315bdd467a0e41f9a375fbe03cbe6b7 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 7 Oct 2016 16:58:39 -0400 Subject: [PATCH 05/20] FIXME: add some test .c files to root dir --- test-asm.c | 15 +++++++++++++++ test-return-const.c | 4 ++++ test-switch.c | 22 ++++++++++++++++++++++ times-two.c | 4 ++++ 4 files changed, 45 insertions(+) create mode 100644 test-asm.c create mode 100644 test-return-const.c create mode 100644 test-switch.c create mode 100644 times-two.c diff --git a/test-asm.c b/test-asm.c new file mode 100644 index 0000000..014cb25 --- /dev/null +++ b/test-asm.c @@ -0,0 +1,15 @@ +#include + +uint64_t +get_timestamp (void) +{ + uint64_t msr; + + asm volatile ("rdtsc\n\t" // Returns the time in EDX:EAX. + "shl $32, %%rdx\n\t" // Shift the upper bits left. + "or %%rdx, %0" // 'Or' in the lower bits. + : "=a" (msr) + : + : "rdx"); + return msr; +} diff --git a/test-return-const.c b/test-return-const.c new file mode 100644 index 0000000..d301774 --- /dev/null +++ b/test-return-const.c @@ -0,0 +1,4 @@ +int test_returning_constant (void) +{ + return 42; +} diff --git a/test-switch.c b/test-switch.c new file mode 100644 index 0000000..746b4e2 --- /dev/null +++ b/test-switch.c @@ -0,0 +1,22 @@ +int test_switch (int i, int j, int k) +{ + switch (i) + { + case -1: + return 34; + case 0 ... 9: + return i * 2; + case 23: + return j + k; + case 24: + return j - k; + case 10: + return j * k; + case 11: + return j / k; + case 12: + return j % k; + default: + return j+k; + } +} diff --git a/times-two.c b/times-two.c new file mode 100644 index 0000000..9430927 --- /dev/null +++ b/times-two.c @@ -0,0 +1,4 @@ +int times_two (int i) +{ + return i * 2; +} -- 1.8.5.3