-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: update test design like cglm library and drop cmocka
- Loading branch information
Showing
16 changed files
with
396 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
AC_PREREQ([2.69]) | ||
AC_INIT([ds], [0.2.1], [[email protected]]) | ||
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) | ||
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects serial-tests]) | ||
|
||
AC_CONFIG_MACRO_DIR([m4]) | ||
AC_CONFIG_SRCDIR([src/]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (c), Recep Aslantas. | ||
* | ||
* MIT License (MIT), http://opensource.org/licenses/MIT | ||
* Full license can be found in the LICENSE file | ||
*/ | ||
|
||
#ifndef tests_common_h | ||
#define tests_common_h | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
typedef struct test_status_t { | ||
const char *msg; | ||
int status; | ||
} test_status_t; | ||
|
||
typedef test_status_t (*fntest)(void); | ||
|
||
typedef struct test_entry_t { | ||
char *name; | ||
fntest entry; | ||
int ret; | ||
int show_output; | ||
} test_entry_t; | ||
|
||
#define RESET "\033[0m" | ||
#define BLACK "\033[30m" /* Black */ | ||
#define RED "\033[31m" /* Red */ | ||
#define GREEN "\033[32m" /* Green */ | ||
#define YELLOW "\033[33m" /* Yellow */ | ||
#define BLUE "\033[34m" /* Blue */ | ||
#define MAGENTA "\033[35m" /* Magenta */ | ||
#define CYAN "\033[36m" /* Cyan */ | ||
#define WHITE "\033[37m" /* White */ | ||
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ | ||
#define BOLDRED "\033[1m\033[31m" /* Bold Red */ | ||
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ | ||
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ | ||
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ | ||
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ | ||
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ | ||
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ | ||
|
||
#define TEST_DECLARE(FUN) test_status_t test_ ## FUN(void); | ||
#define TEST_ENTRY(FUN) { #FUN, test_ ## FUN, 0, 0 }, | ||
#define TEST_LIST static test_entry_t tests[] = | ||
|
||
/* __VA_ARGS__ workaround for MSVC: https://stackoverflow.com/a/5134656 */ | ||
#define EXPAND(x) x | ||
|
||
#define TEST_OK 1 | ||
#define TEST_SUCCESS return (test_status_t){NULL, TEST_OK}; | ||
|
||
#define TEST_IMPL_ARG1(FUN) \ | ||
test_status_t test_ ## FUN (void); \ | ||
test_status_t test_ ## FUN() | ||
|
||
#define TEST_IMPL_ARG2(PREFIX, FUN) TEST_IMPL_ARG1(PREFIX ## FUN) | ||
#define TEST_IMPL_ARG3(arg1, arg2, arg3, ...) arg3 | ||
|
||
#define TEST_IMPL_CHOOSER(...) \ | ||
EXPAND(TEST_IMPL_ARG3(__VA_ARGS__, TEST_IMPL_ARG2, TEST_IMPL_ARG1)) | ||
|
||
#define TEST_IMPL(...) EXPAND(TEST_IMPL_CHOOSER(__VA_ARGS__)(__VA_ARGS__)) | ||
|
||
#define ASSERT_EXT(expr, msg) \ | ||
if (!(expr)) { \ | ||
fprintf(stderr, \ | ||
RED " assert fail" RESET \ | ||
" in " BOLDCYAN "%s " RESET \ | ||
"on " BOLDMAGENTA "line %d" RESET \ | ||
" : " BOLDWHITE " ASSERT(%s)\n" RESET, \ | ||
__FILE__, \ | ||
__LINE__, \ | ||
#expr); \ | ||
return (test_status_t){msg, 0}; \ | ||
} | ||
|
||
#define ASSERT_ARG1(expr) ASSERT_EXT(expr, NULL) | ||
#define ASSERT_ARG2(expr, msg) ASSERT_EXT(expr, msg) | ||
#define ASSERT_ARG3(arg1, arg2, arg3, ...) arg3 | ||
|
||
#define ASSERT_CHOOSER(...) ASSERT_ARG3(__VA_ARGS__, ASSERT_ARG2, ASSERT_ARG1) | ||
#define ASSERT(...) do { ASSERT_CHOOSER(__VA_ARGS__)(__VA_ARGS__) } while(0); | ||
#define ASSERTIFY(expr) do { \ | ||
test_status_t ts; \ | ||
ts = expr; \ | ||
if (ts.status != TEST_OK) { \ | ||
fprintf(stderr, \ | ||
RED " assert fail" RESET \ | ||
" in " BOLDCYAN "%s " RESET \ | ||
"on " BOLDMAGENTA "line %d" RESET \ | ||
" : " BOLDWHITE " ASSERTIFY(%s)\n" RESET, \ | ||
__FILE__, \ | ||
__LINE__, \ | ||
#expr); \ | ||
return (test_status_t){ts.msg, 0}; \ | ||
} \ | ||
} while(0); | ||
|
||
#if defined(_WIN32) | ||
# define drand48() ((float)(rand() / (RAND_MAX + 1.0))) | ||
# define OK_TEXT "ok:" | ||
# define FAIL_TEXT "fail:" | ||
# define FINAL_TEXT "^_^" | ||
#else | ||
# define OK_TEXT "✔︎" | ||
# define FAIL_TEXT "𐄂" | ||
# define FINAL_TEXT "🎉" | ||
#endif | ||
|
||
#endif /* common_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (c), Recep Aslantas. | ||
* | ||
* MIT License (MIT), http://opensource.org/licenses/MIT | ||
* Full license can be found in the LICENSE file | ||
*/ | ||
|
||
#include "include/common.h" | ||
#include "tests.h" | ||
|
||
#include <stdlib.h> | ||
#include <time.h> | ||
#include <string.h> | ||
|
||
#define TARGET_NAME "libds" | ||
|
||
int | ||
main(int argc, const char * argv[]) { | ||
test_entry_t *entry; | ||
test_status_t st; | ||
int32_t i, count, passed, failed, maxlen; | ||
double start, end, elapsed, total; | ||
|
||
passed = failed = maxlen = 0; | ||
total = 0.0; | ||
count = sizeof(tests) / sizeof(tests[0]); | ||
|
||
fprintf(stderr, CYAN "\nWelcome to %s tests\n\n" RESET, TARGET_NAME); | ||
|
||
for (i = 0; i < count; i++) { | ||
int32_t len; | ||
|
||
entry = tests + i; | ||
len = (int32_t)strlen(entry->name); | ||
|
||
if (len > maxlen) | ||
maxlen = len; | ||
} | ||
|
||
maxlen += 5; | ||
|
||
fprintf(stderr, | ||
BOLDWHITE " %-*s %-*s\n", | ||
maxlen, "Test Name", maxlen, "Elapsed Time"); | ||
|
||
for (i = 0; i < count; i++) { | ||
entry = tests + i; | ||
start = clock(); | ||
st = entry->entry(); | ||
end = clock(); | ||
elapsed = (end - start) / CLOCKS_PER_SEC; | ||
total += elapsed; | ||
|
||
if (!st.status) { | ||
fprintf(stderr, | ||
BOLDRED " " FAIL_TEXT BOLDWHITE " %s " RESET, entry->name); | ||
if (st.msg) { | ||
fprintf(stderr, | ||
YELLOW "- %s" RESET, | ||
st.msg); | ||
} | ||
|
||
fprintf(stderr, "\n"); | ||
|
||
failed++; | ||
} else { | ||
fprintf(stderr, GREEN " " OK_TEXT RESET " %-*s ", maxlen, entry->name); | ||
|
||
if (elapsed > 0.01) | ||
fprintf(stderr, YELLOW "%.2fs", elapsed); | ||
else | ||
fprintf(stderr, "0"); | ||
|
||
fprintf(stderr, "\n" RESET); | ||
passed++; | ||
} | ||
} | ||
|
||
if (failed == 0) { | ||
fprintf(stderr, | ||
BOLDGREEN "\n All tests are passed " FINAL_TEXT "\n" RESET); | ||
} | ||
|
||
fprintf(stderr, | ||
CYAN "\n%s test results (%0.2fs):\n" RESET | ||
"--------------------------\n" | ||
|
||
MAGENTA "%d" RESET " tests are runned, " | ||
GREEN "%d" RESET " %s passed, " | ||
RED "%d" RESET " %s failed\n\n" RESET, | ||
TARGET_NAME, | ||
total, | ||
count, | ||
passed, | ||
passed > 1 ? "are" : "is", | ||
failed, | ||
failed > 1 ? "are" : "is"); | ||
|
||
return failed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.