From cf1d1f6e4b1138a5a841a47a2cba4aacdcaf0d72 Mon Sep 17 00:00:00 2001 From: Mahircan Gul Date: Mon, 18 Jul 2016 16:05:20 +0200 Subject: Add unit-test for CPU mapping parsing - Decompose read_mapping into two functions: *read_mapping* which reads CPU mapping data as string from file, and *set_mapping* that actually sets the cpu_set_t according to the mapping - Add unit test for setting cpu_set_t to various CPU indexes --- tests/core_api.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests') diff --git a/tests/core_api.c b/tests/core_api.c index feb60c5..065c1fc 100644 --- a/tests/core_api.c +++ b/tests/core_api.c @@ -193,6 +193,44 @@ TESTCASE(ctrl_page_writable, ALL, ctrl_page[32] = 0x12345678; } +TESTCASE(set_cpu_mapping, LITMUS, + "task's CPU affinity is set to CPU set that is read from file") +{ + char buf[4096/4 /* enough chars for hex data (4 CPUs per char) */ + + 4096/(4*8) /* for commas (separate groups of 8 chars) */ + + 1] = {0}; /* for \0 */ + int len; + cpu_set_t *set; + size_t sz; + + /*set affinity to CPU 0 */ + strcpy(buf, "20"); + len = strnlen(buf, sizeof(buf)); + set_mapping(buf, len, &set, &sz); + ASSERT( CPU_ISSET_S(5, sz, set) ); + + /*set affinity to CPU 29 */ + strcpy(buf, "20000000"); + len = strnlen(buf, sizeof(buf)); + set_mapping(buf, len, &set, &sz); + ASSERT( CPU_ISSET_S(29, sz, set) ); + + /*set affinity to CPUS 27 and 39 */ + strcpy(buf, "80,08000000"); + len = strnlen(buf, sizeof(buf)); + set_mapping(buf, len, &set, &sz); + ASSERT( CPU_ISSET_S(27, sz, set) ); + ASSERT( CPU_ISSET_S(39, sz, set) ); + + /*set affinity to CPUS 96 */ + strcpy(buf, "1,00000000,00000000,00000000"); + len = strnlen(buf, sizeof(buf)); + set_mapping(buf, len, &set, &sz); + ASSERT( CPU_ISSET_S(96, sz, set) ); + +} + + TESTCASE(suspended_admission, LITMUS, "admission control handles suspended tasks correctly") -- cgit v1.2.2