Skip to content

Commit 9127c4b

Browse files
committed
tests: Cleanup converting int result to string
Introduce TC_RESULT_TO_STR to convert from an integer test result to a string like "PASS", "FAIL", "SKIP". Do this to remove the defines of PASS/FAIL/SKIP since those names might get used by other code and to have a single consistent way of doing the conversion. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
1 parent fa83a4d commit 9127c4b

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

tests/crypto/ctr_prng/src/ctr_prng.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,6 @@ void test_robustness(void)
535535
TC_PRINT("CTR PRNG robustness test succeeded\n");
536536
}
537537

538-
#define RC_STR(rc) (rc == TC_PASS ? PASS : FAIL)
539-
540538
/*
541539
* Main task to test CTR PRNG
542540
*/
@@ -551,7 +549,8 @@ void test_ctr_prng_vector(void)
551549
elements = (int)sizeof(vectors) / sizeof(vectors[0]);
552550
for (i = 0; i < elements; i++) {
553551
rc = test_prng_vector(&vectors[i]);
554-
TC_PRINT("[%s] test_prng_vector #%d\n", RC_STR(rc), i);
552+
TC_PRINT("[%s] test_prng_vector #%d\n",
553+
TC_RESULT_TO_STR(rc), i);
555554

556555
/**TESTPOINT: Check if test passed*/
557556
zassert_false(rc, "CTR PRNG vector test failed");

tests/include/tc_util.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,23 @@
5757
/* stack size and priority for test suite task */
5858
#define TASK_STACK_SIZE (1024 * 2)
5959

60-
#define FAIL "FAIL"
61-
#define PASS "PASS"
62-
#define SKIP "SKIP"
6360
#define FMT_ERROR "%s - %s@%d. "
6461

6562
#define TC_PASS 0
6663
#define TC_FAIL 1
6764
#define TC_SKIP 2
6865

66+
static __unused const char *TC_RESULT_STR[] = {
67+
[TC_PASS] = "PASS",
68+
[TC_FAIL] = "FAIL",
69+
[TC_SKIP] = "SKIP",
70+
};
71+
72+
#define TC_RESULT_TO_STR(result) TC_RESULT_STR[result]
73+
6974
#define TC_ERROR(fmt, ...) \
7075
do { \
71-
PRINT_DATA(FMT_ERROR, FAIL, __func__, __LINE__); \
76+
PRINT_DATA(FMT_ERROR, "FAIL", __func__, __LINE__); \
7277
PRINT_DATA(fmt, ##__VA_ARGS__); \
7378
} while (0)
7479

@@ -79,13 +84,7 @@
7984
/* prints result and the function name */
8085
#define _TC_END_RESULT(result, func) \
8186
do { \
82-
if ((result) == TC_PASS) { \
83-
TC_END(result, "%s - %s\n", PASS, func); \
84-
} else if ((result) == TC_FAIL) { \
85-
TC_END(result, "%s - %s\n", FAIL, func); \
86-
} else { \
87-
TC_END(result, "%s - %s\n", SKIP, func); \
88-
} \
87+
TC_END(result, "%s - %s\n", TC_RESULT_TO_STR(result), func); \
8988
PRINT_LINE; \
9089
} while (0)
9190
#define TC_END_RESULT(result) \

tests/net/lib/http_header_fields/src/main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,6 @@ int test_header_cr_no_lf_error(int req)
821821
return TC_FAIL;
822822
}
823823

824-
#define RC_STR(rc) (rc == TC_PASS ? PASS : FAIL)
825-
826824
void test_http_header_fields(void)
827825
{
828826
int rc;

tests/net/lib/mqtt_packet/src/mqtt_packet.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include <misc/util.h> /* for ARRAY_SIZE */
1010
#include <ztest.h>
1111

12-
#define RC_STR(rc) (rc == TC_PASS ? PASS : FAIL)
13-
1412
#define CLIENTID "zephyr"
1513
#define CLIENTID_LEN 6
1614
#define TOPIC "sensors"
@@ -735,7 +733,7 @@ int eval_buffers(u8_t *buf, u16_t buf_len, u8_t *expected,
735733
return TC_PASS;
736734

737735
exit_eval:
738-
TC_PRINT("%s\n", FAIL);
736+
TC_PRINT("FAIL\n");
739737
TC_PRINT("Computed:");
740738
print_array(buf, buf_len);
741739
TC_PRINT("Expected:");
@@ -1020,7 +1018,8 @@ void test_mqtt_packet(void)
10201018
}
10211019

10221020
rc = test->eval_fcn(test);
1023-
TC_PRINT("[%s] %d - %s\n", RC_STR(rc), i + 1, test->test_name);
1021+
TC_PRINT("[%s] %d - %s\n", TC_RESULT_TO_STR(rc), i + 1,
1022+
test->test_name);
10241023

10251024
/**TESTPOINT: Check eval_fcn*/
10261025
zassert_false(rc, "mqtt_packet test error");

0 commit comments

Comments
 (0)