Update test framework

This commit is contained in:
Lamdonn 2024-11-16 13:36:54 +08:00
parent a2125c2b9f
commit e440a96e99
61 changed files with 2839 additions and 494 deletions

View File

@ -56,7 +56,7 @@ CFLAG += -std=$(CSTD)
include $(TESTSPACE)/test.mk include $(TESTSPACE)/test.mk
TESTSRC += $(APPLICATION_PATH)/main.c TESTSRC += $(APPLICATION_PATH)/main.c
TESTSRC += $(TEST_SRC) TESTSRC += $(patsubst %,$(TESTSPACE)/test_%.c,$(TEST_LIST))
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
UNAME := Windows UNAME := Windows
@ -96,6 +96,10 @@ $(OBJP)/%.o:%.c
app:${TARP} app:${TARP}
$(TEST_LIST): %: $(TESTSPACE)/test_%.c
@ mkdir -p $(BINP)
@ $(CC) $(CFLAG) -o $(BINP)/$@ $< -DTEST_TARGET_$@ $(LIBS) -l$(LIB) -lm
# lib # lib
lib:$(LIBO) lib:$(LIBO)
@ $(AR) -crv $(LIBA) $(LIBO) @ $(AR) -crv $(LIBA) $(LIBO)
@ -114,6 +118,9 @@ help:
@echo "" @echo ""
@echo " lib - Build the library ($(LIB))" @echo " lib - Build the library ($(LIB))"
@echo "" @echo ""
@echo " [test] - Build test app, and link to $(LIB) lib"
@echo " Test target: $(TEST_LIST)"
@echo ""
@echo " run - Execute the default application" @echo " run - Execute the default application"
@echo "" @echo ""
@echo " install - Install the library" @echo " install - Install the library"
@ -127,6 +134,7 @@ help:
@echo " clean - Remove build artifacts" @echo " clean - Remove build artifacts"
@echo "" @echo ""
@echo " help - Show this help message" @echo " help - Show this help message"
@echo ""
.PHONY:clean .PHONY:clean

View File

@ -14,12 +14,12 @@
#define __calculate_H #define __calculate_H
/* Version infomation */ /* Version infomation */
#define CALCULATE_V_MAJOR 1 #define CALCULATE_V_MAJOR 1
#define CALCULATE_V_MINOR 0 #define CALCULATE_V_MINOR 0
#define CALCULATE_V_REVISE 0 #define CALCULATE_V_PATCH 0
/* Configuration information */ /* Configuration information */
#define CALCULATE_EXFUNC_MAX 32 /**< The maximum extern function count supported */ #define CALCULATE_EXFUNC_MAX 32 /**< The maximum extern function count supported */
/** /**
* \brief enter a calculation expression to calculate the result, support 'in_function_table[]' table operation function * \brief enter a calculation expression to calculate the result, support 'in_function_table[]' table operation function

View File

@ -44,18 +44,18 @@ static struct COMMAND base[COMMAND_COUNT_MAX] =
static void usage(void) static void usage(void)
{ {
printf( printf(
"Usage:\n" "Usage: cmd [opt] [arg]\n"
"Enter the command line to execute the corresponding command\n" "Enter the command line to execute the corresponding command\n"
"\n" "\n"
"OPTIONS\n" "options:\n"
"[-l] : Print currently supported commands\n" " -l Print currently supported commands\n"
"[-n] : Print the number of currently supported commands\n" " -n Print the number of currently supported commands\n"
"[-h] : Print help\n" " -c <config> Print the configuration information of the current command module\n"
"[-v] : Print version\n" " `argc` : The maximum number of parameters supported for parsing in the input command\n"
"[-c] : Print the configuration information of the current command module\n" " `line` : The maximum length supported for parsing in the input command\n"
" `argc` : The maximum number of parameters supported for parsing in the input command\n" " `count` : The maximum command count supported\n"
" `line` : The maximum length supported for parsing in the input command\n" " -h Print help\n"
" `count` : The maximum command count supported\n" " -v Print version\n"
); );
} }
@ -75,7 +75,7 @@ static int cmd(int argc, char *argv[])
command_opt_init(); command_opt_init();
while (1) while (1)
{ {
opt = command_getopt(argc, argv, "lnhvc:"); opt = command_getopt(argc, argv, "lnc:hv");
if (opt == -1) break; if (opt == -1) break;
switch (opt) switch (opt)
@ -90,12 +90,6 @@ static int cmd(int argc, char *argv[])
case 'n': case 'n':
printf("%d\r\n", command_num); printf("%d\r\n", command_num);
break; break;
case 'h' :
usage();
break;
case 'v' :
printf("command version %d.%d.%d\r\n", COMAMND_V_MAJOR, COMAMND_V_MINOR, COMAMND_V_PATCH);
break;
case 'c' : case 'c' :
if (!strcmp(command_optarg, "argc")) if (!strcmp(command_optarg, "argc"))
{ {
@ -114,12 +108,16 @@ static int cmd(int argc, char *argv[])
printf("no such optarg: %s\r\n", command_optarg); printf("no such optarg: %s\r\n", command_optarg);
} }
break; break;
case 'v' :
printf("command version %d.%d.%d\r\n", COMMAND_V_MAJOR, COMMAND_V_MINOR, COMMAND_V_PATCH);
return 0;
case '?': case '?':
printf("Unknown option `%c`\r\n", command_optopt); printf("Unknown option `%c`\r\n", command_optopt);
return -1; return -1;
case 'h' :
default: default:
usage(); usage();
break; return 0;
} }
} }

View File

@ -15,14 +15,14 @@
#define __command_H #define __command_H
/* Version infomation */ /* Version infomation */
#define COMAMND_V_MAJOR 1 #define COMMAND_V_MAJOR 1
#define COMAMND_V_MINOR 0 #define COMMAND_V_MINOR 0
#define COMAMND_V_PATCH 0 #define COMMAND_V_PATCH 1
/* Configuration information */ /* Configuration information */
#define COMMAND_ARGC_MAX 16 /**< The maximum number of parameters supported for parsing in the input command */ #define COMMAND_ARGC_MAX 16 /**< The maximum number of parameters supported for parsing in the input command */
#define COMMAND_LINE_MAX 256 /**< The maximum length supported for parsing in the input command */ #define COMMAND_LINE_MAX 256 /**< The maximum length supported for parsing in the input command */
#define COMMAND_COUNT_MAX 32 /**< The maximum command count supported */ #define COMMAND_COUNT_MAX 128 /**< The maximum command count supported */
/* Return value of command module /* Return value of command module
* Negative return values are used internally by the module * Negative return values are used internally by the module

View File

@ -15,7 +15,7 @@
/* Version infomation */ /* Version infomation */
#define FSM_V_MAJOR 1 #define FSM_V_MAJOR 1
#define FSM_V_MINOR 0 #define FSM_V_MINOR 0
#define FSM_V_REVISE 0 #define FSM_V_PATCH 0
/* State transition type definition */ /* State transition type definition */
typedef struct typedef struct

View File

@ -16,7 +16,7 @@
/* Version infomation */ /* Version infomation */
#define KERN_V_MAJOR 1 #define KERN_V_MAJOR 1
#define KERN_V_MINOR 0 #define KERN_V_MINOR 0
#define KERN_V_REVISE 0 #define KERN_V_PATCH 0
/* task type */ /* task type */
typedef unsigned int task_t; typedef unsigned int task_t;

View File

@ -16,7 +16,7 @@
/* Version infomation */ /* Version infomation */
#define OSCP_V_MAJOR 1 #define OSCP_V_MAJOR 1
#define OSCP_V_MINOR 0 #define OSCP_V_MINOR 0
#define OSCP_V_REVISE 0 #define OSCP_V_PATCH 0
/* Display resolution, which is the maximum horizontal value that a numerical value can display */ /* Display resolution, which is the maximum horizontal value that a numerical value can display */
#define RESOLUTION 100 #define RESOLUTION 100

View File

@ -18,7 +18,7 @@
/* Version infomation */ /* Version infomation */
#define DICT_V_MAJOR 1 #define DICT_V_MAJOR 1
#define DICT_V_MINOR 0 #define DICT_V_MINOR 0
#define DICT_V_REVISE 0 #define DICT_V_PATCH 0
/** Using dict error area /** Using dict error area
* when there is an error in the read or write operation, * when there is an error in the read or write operation,

View File

@ -32,8 +32,14 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#define DES_ENCRYPT 0 /* Version infomation */
#define DES_DECRYPT 1
#define ENCRYPT_V_MAJOR 1
#define ENCRYPT_V_MINOR 0
#define ENCRYPT_V_PATCH 0
#define DES_ENCRYPT 0
#define DES_DECRYPT 1
int des_set_key(const uint8_t key[8]); int des_set_key(const uint8_t key[8]);
int des_crypt_ecb(const uint8_t input[8], uint8_t output[8], uint8_t mode); int des_crypt_ecb(const uint8_t input[8], uint8_t output[8], uint8_t mode);

View File

@ -15,6 +15,10 @@
#include <stdint.h> #include <stdint.h>
#define HASH_V_MAJOR 1
#define HASH_V_MINOR 0
#define HASH_V_PATCH 0
/* Hash algorithm declare /* Hash algorithm declare
* *
* All method interface types are consistent, and the external use methods are also consistent. * All method interface types are consistent, and the external use methods are also consistent.

View File

@ -18,7 +18,7 @@
/* Version infomation */ /* Version infomation */
#define CPUL_V_MAJOR 0 #define CPUL_V_MAJOR 0
#define CPUL_V_MINOR 1 #define CPUL_V_MINOR 1
#define CPUL_V_PATcH 0 #define CPUL_V_PATCH 0
#define CPUL_GEN_BSIZE 4 #define CPUL_GEN_BSIZE 4

View File

@ -22,7 +22,7 @@
/* Version infomation */ /* Version infomation */
#define RAMT_V_MAJOR 0 #define RAMT_V_MAJOR 0
#define RAMT_V_MINOR 1 #define RAMT_V_MINOR 1
#define RAMT_V_REVISE 0 #define RAMT_V_PATCH 0
// Define different RAM test modes // Define different RAM test modes
#define RAMT_MODE_NORMAL ((uint32_t)0x00000001) // Normal read/write test #define RAMT_MODE_NORMAL ((uint32_t)0x00000001) // Normal read/write test

View File

@ -20,7 +20,7 @@
/* Version infomation */ /* Version infomation */
#define ROMT_V_MAJOR 0 #define ROMT_V_MAJOR 0
#define ROMT_V_MINOR 1 #define ROMT_V_MINOR 1
#define ROMT_V_REVISE 0 #define ROMT_V_PATCH 0
#define ROMT_MODE_READ ((uint32_t)0x00000001) ///< Mode for reading from ROM #define ROMT_MODE_READ ((uint32_t)0x00000001) ///< Mode for reading from ROM
#define ROMT_MODE_WRITE ((uint32_t)0x00000002) ///< Mode for writing to ROM #define ROMT_MODE_WRITE ((uint32_t)0x00000002) ///< Mode for writing to ROM

View File

@ -23,7 +23,7 @@
/* Version infomation */ /* Version infomation */
#define UNITT_V_MAJOR 0 #define UNITT_V_MAJOR 0
#define UNITT_V_MINOR 1 #define UNITT_V_MINOR 1
#define UNITT_V_PATcH 0 #define UNITT_V_PATCH 0
// Type definition for a clock function // Type definition for a clock function
typedef uint64_t (*unitt_clock_t)(); typedef uint64_t (*unitt_clock_t)();

View File

@ -1,55 +1,43 @@
TEST_LIST += init
TEST_SRC = TEST_LIST += kern
TEST_INC = TEST_LIST += valloc
TEST_LIST += arg
#---------------------------------------- TEST_LIST += vstd
# test sources TEST_LIST += vlog
#---------------------------------------- TEST_LIST += ini
# TEST_SRC += $(TESTSPACE)/test_init.c TEST_LIST += txls
# TEST_SRC += $(TESTSPACE)/test_kern.c TEST_LIST += xml
# TEST_SRC += $(TESTSPACE)/test_valloc.c TEST_LIST += csv
# TEST_SRC += $(TESTSPACE)/test_arg.c TEST_LIST += json
# TEST_SRC += $(TESTSPACE)/test_vstd.c TEST_LIST += vector
# TEST_SRC += $(TESTSPACE)/test_vlog.c TEST_LIST += list
# TEST_SRC += $(TESTSPACE)/test_ini.c TEST_LIST += str
# TEST_SRC += $(TESTSPACE)/test_txls.c TEST_LIST += queue
# TEST_SRC += $(TESTSPACE)/test_xml.c TEST_LIST += stack
# TEST_SRC += $(TESTSPACE)/test_csv.c TEST_LIST += deque
# TEST_SRC += $(TESTSPACE)/test_json.c TEST_LIST += set
# TEST_SRC += $(TESTSPACE)/test_vector.c TEST_LIST += dict
# TEST_SRC += $(TESTSPACE)/test_list.c TEST_LIST += map
# TEST_SRC += $(TESTSPACE)/test_str.c TEST_LIST += heap
# TEST_SRC += $(TESTSPACE)/test_queue.c TEST_LIST += tree
# TEST_SRC += $(TESTSPACE)/test_stack.c TEST_LIST += graph
# TEST_SRC += $(TESTSPACE)/test_deque.c TEST_LIST += encrypt
# TEST_SRC += $(TESTSPACE)/test_set.c TEST_LIST += calculate
# TEST_SRC += $(TESTSPACE)/test_dict.c TEST_LIST += command
# TEST_SRC += $(TESTSPACE)/test_map.c TEST_LIST += check
# TEST_SRC += $(TESTSPACE)/test_heap.c TEST_LIST += crc
# TEST_SRC += $(TESTSPACE)/test_tree.c TEST_LIST += sort
# TEST_SRC += $(TESTSPACE)/test_graph.c TEST_LIST += hash
# TEST_SRC += $(TESTSPACE)/test_rbtree.c TEST_LIST += pid
# TEST_SRC += $(TESTSPACE)/test_pthread.c TEST_LIST += search
# TEST_SRC += $(TESTSPACE)/test_encrypt.c TEST_LIST += filter
# TEST_SRC += $(TESTSPACE)/test_calculate.c TEST_LIST += oscp
# TEST_SRC += $(TESTSPACE)/test_command.c TEST_LIST += tool
# TEST_SRC += $(TESTSPACE)/test_check.c TEST_LIST += sList
# TEST_SRC += $(TESTSPACE)/test_crc.c TEST_LIST += dList
# TEST_SRC += $(TESTSPACE)/test_sort.c TEST_LIST += cQueue
# TEST_SRC += $(TESTSPACE)/test_hash.c TEST_LIST += intl
# TEST_SRC += $(TESTSPACE)/test_pid.c TEST_LIST += ramt
# TEST_SRC += $(TESTSPACE)/test_search.c TEST_LIST += cpul
# TEST_SRC += $(TESTSPACE)/test_filter.c TEST_LIST += date
# TEST_SRC += $(TESTSPACE)/test_oscp.c TEST_LIST += unitt
# TEST_SRC += $(TESTSPACE)/test_tool.c
# TEST_SRC += $(TESTSPACE)/test_sList.c
# TEST_SRC += $(TESTSPACE)/test_dList.c
# TEST_SRC += $(TESTSPACE)/test_cQueue.c
# TEST_SRC += $(TESTSPACE)/test_intl.c
# TEST_SRC += $(TESTSPACE)/test_ramt.c
# TEST_SRC += $(TESTSPACE)/test_cpul.c
# TEST_SRC += $(TESTSPACE)/test_date.c
TEST_SRC += $(TESTSPACE)/test_unitt.c
export TEST_SRC TEST_INC

View File

@ -1,11 +1,55 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_arg)
#include <varch/command.h>
#include <varch/arg.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "arg.h" #include "arg.h"
#endif
static void test(void) static void usage(void)
{ {
printf(
"Usage: arg [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("arg version %d.%d.%d\r\n", ARG_V_MAJOR, ARG_V_MINOR, ARG_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
printf("ARG_MAX %d\r\n", ARG_MAX); printf("ARG_MAX %d\r\n", ARG_MAX);
printf("ARGC %d\r\n", ARGC()); printf("ARGC %d\r\n", ARGC());
@ -21,5 +65,19 @@ static void test(void)
printf("ARGS %s\r\n", ARGS(0, "arg0", "arg1", "arg2")); printf("ARGS %s\r\n", ARGS(0, "arg0", "arg1", "arg2"));
printf("ARGS %s\r\n", ARGS(1, "arg0", "arg1", "arg2")); printf("ARGS %s\r\n", ARGS(1, "arg0", "arg1", "arg2"));
printf("ARGS %s\r\n", ARGS(2, "arg0", "arg1", "arg2")); printf("ARGS %s\r\n", ARGS(2, "arg0", "arg1", "arg2"));
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_arg)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_arg(void)
{
command_export("arg", test);
}
init_export_app(test_arg);
#endif

View File

@ -1,10 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_cQueue)
#include <varch/command.h>
#include <varch/cQueue.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "cQueue.h" #include "cQueue.h"
#endif
void test_int(void) void test_int(void)
{ {
@ -63,13 +67,61 @@ void test_struct(void)
} }
} }
static void test(void) static void usage(void)
{ {
printf("cQueue test!\r\n"); printf(
"Usage: cQueue [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("cQueue version %d.%d.%d\r\n", CQUEUE_V_MAJOR, CQUEUE_V_MINOR, CQUEUE_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_int(); // test_int();
test_struct(); test_struct();
v_check_unfree(); return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_cQueue)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_cQueue(void)
{
command_export("cQueue", test);
}
init_export_app(test_cQueue);
#endif

View File

@ -1,15 +1,18 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "init.h"
#include "tool.h"
#include "valloc.h"
#include "calculate.h"
#include <float.h> #include <float.h>
#include <math.h> #include <math.h>
#include "command.h"
#include <math.h> #include <math.h>
#include <ctype.h> #include <ctype.h>
#if defined(TEST_TARGET_calculate)
#include <varch/command.h>
#include <varch/calculate.h>
#else
#include "init.h"
#include "command.h"
#include "calculate.h"
#endif
static int command_calculate(int argc, char *argv[]) static int command_calculate(int argc, char *argv[])
{ {
@ -40,8 +43,46 @@ static double K()
return 1024.0; return 1024.0;
} }
static void test(void) static void usage(void)
{ {
printf(
"Usage: calculate [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("calculate version %d.%d.%d\r\n", CALCULATE_V_MAJOR, CALCULATE_V_MINOR, CALCULATE_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
printf("mul %lf\r\n", calculate(" ( 99 * 3 ) ")); printf("mul %lf\r\n", calculate(" ( 99 * 3 ) "));
printf("min %lf\r\n", calculate(" min (12, 3)")); printf("min %lf\r\n", calculate(" min (12, 3)"));
printf("sin %lf\r\n", calculate("sin ( 11 / 2 * pi ) + 100 ")); printf("sin %lf\r\n", calculate("sin ( 11 / 2 * pi ) + 100 "));
@ -50,5 +91,19 @@ static void test(void)
calculate_export("K", K, 0); calculate_export("K", K, 0);
command_export("cal", command_calculate); command_export("cal", command_calculate);
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_calculate)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_calculate(void)
{
command_export("calculate", test);
}
init_export_app(test_calculate);
#endif

View File

@ -3,10 +3,14 @@
#include <string.h> #include <string.h>
#include <float.h> #include <float.h>
#include <math.h> #include <math.h>
#if defined(TEST_TARGET_check)
#include <varch/command.h>
#include <varch/check.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "check.h" #include "check.h"
#endif
typedef uint8_t (*checkType)(uint8_t* data, uint32_t len); typedef uint8_t (*checkType)(uint8_t* data, uint32_t len);
@ -17,8 +21,46 @@ static checkType checkFunTable[] = {
check_xor, check_xor,
}; };
static void test(void) static void usage(void)
{ {
printf(
"Usage: check [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("check version %d.%d.%d\r\n", CHECK_V_MAJOR, CHECK_V_MINOR, CHECK_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
char *testSample[] = { char *testSample[] = {
"Hello", "Hello",
"check algorithms", "check algorithms",
@ -34,5 +76,19 @@ static void test(void)
printf("Func %d, check %02X\r\n", j, check); printf("Func %d, check %02X\r\n", j, check);
} }
} }
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_check)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_check(void)
{
command_export("check", test);
}
init_export_app(test_check);
#endif

View File

@ -1,10 +1,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_command)
#include <varch/command.h>
#else
#include "init.h" #include "init.h"
#include "tool.h"
#include "valloc.h"
#include "command.h" #include "command.h"
#endif
int func1(int argc, char *argv[]) int func1(int argc, char *argv[])
{ {
@ -29,8 +31,46 @@ int func3(int argc, char *argv[])
return 1; return 1;
} }
static void test(void) static void usage(void)
{ {
printf(
"Usage: command [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("command version %d.%d.%d\r\n", COMMAND_V_MAJOR, COMMAND_V_MINOR, COMMAND_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
command_export("func1", func1); command_export("func1", func1);
command_export("func2", func2); command_export("func2", func2);
command_export("func3", func3); command_export("func3", func3);
@ -48,5 +88,19 @@ static void test(void)
// command("func1 1\\ 2 3"); // command("func1 1\\ 2 3");
// printf("--------------------------\r\n"); // printf("--------------------------\r\n");
// command("func1 \"1 2 3\""); // command("func1 \"1 2 3\"");
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_command)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_command(void)
{
command_export("command", test);
}
init_export_app(test_command);
#endif

View File

@ -10,8 +10,14 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <sched.h> #include <sched.h>
#if defined(TEST_TARGET_cpul)
#include <varch/command.h>
#include <varch/cpul.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "cpul.h" #include "cpul.h"
#endif
#define CORE_NUM_MAX 32 #define CORE_NUM_MAX 32
#define LINE_BUFFER_SIZE 1024 #define LINE_BUFFER_SIZE 1024
@ -164,8 +170,46 @@ void *loadgen_entry(void *ptr)
} }
} }
static void test(void) static void usage(void)
{ {
printf(
"Usage: cpul [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("cpul version %d.%d.%d\r\n", CPUL_V_MAJOR, CPUL_V_MINOR, CPUL_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
int num_cpus = sysconf(_SC_NPROCESSORS_CONF); int num_cpus = sysconf(_SC_NPROCESSORS_CONF);
pthread_t thread_update, thread_gen[num_cpus]; pthread_t thread_update, thread_gen[num_cpus];
int coreid[num_cpus]; int coreid[num_cpus];
@ -196,5 +240,19 @@ static void test(void)
{ {
pthread_join(thread_gen[i], NULL); pthread_join(thread_gen[i], NULL);
} }
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_cpul)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_cpul(void)
{
command_export("cpul", test);
}
init_export_app(test_cpul);
#endif

View File

@ -3,10 +3,14 @@
#include <string.h> #include <string.h>
#include <float.h> #include <float.h>
#include <math.h> #include <math.h>
#if defined(TEST_TARGET_crc)
#include <varch/command.h>
#include <varch/crc.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "crc.h" #include "crc.h"
#endif
uint32_t std_crc(uint8_t* data, uint32_t len, uint32_t index) uint32_t std_crc(uint8_t* data, uint32_t len, uint32_t index)
{ {
@ -42,8 +46,46 @@ uint32_t std_crc(uint8_t* data, uint32_t len, uint32_t index)
return crc; return crc;
} }
static void test(void) static void usage(void)
{ {
printf(
"Usage: crc [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("crc version %d.%d.%d\r\n", CRC_V_MAJOR, CRC_V_MINOR, CRC_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
char *testSample[] = { char *testSample[] = {
"Hello", "Hello",
"crc algorithms", "crc algorithms",
@ -61,5 +103,19 @@ static void test(void)
printf("crc %02d, crc0 %08X, crc1 %08X, same %d\r\n", j, crc0, crc1, (crc0 == crc1) ? 1 : 0); printf("crc %02d, crc0 %08X, crc1 %08X, same %d\r\n", j, crc0, crc1, (crc0 == crc1) ? 1 : 0);
} }
} }
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_crc)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_crc(void)
{
command_export("crc", test);
}
init_export_app(test_crc);
#endif

View File

@ -1,8 +1,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_csv)
#include <varch/command.h>
#include <varch/csv.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "csv.h" #include "csv.h"
#include "valloc.h" #endif
#define READ_FILE "source/application/test/file/read.csv" #define READ_FILE "source/application/test/file/read.csv"
#define WRITE_FILE "source/application/test/file/write.csv" #define WRITE_FILE "source/application/test/file/write.csv"
@ -176,13 +181,64 @@ static void load_demo(void)
csv_delete(csv); csv_delete(csv);
} }
static void test(void) static void usage(void)
{ {
printf(
"Usage: csv [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("csv version %d.%d.%d\r\n", CSV_V_MAJOR, CSV_V_MINOR, CSV_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_dump(); // test_dump();
// test_load(); // test_load();
// dump_demo(); // dump_demo();
load_demo(); load_demo();
printf("use %d\r\n", v_check_used());
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_csv)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_csv(void)
{
command_export("csv", test);
}
init_export_app(test_csv);
#endif

View File

@ -1,10 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_dList)
#include <varch/command.h>
#include <varch/dList.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "dList.h" #include "dList.h"
#endif
static void test_create(void) static void test_create(void)
{ {
@ -254,7 +258,7 @@ static void test_append(void)
if (!dList_append(list, &ap)) goto FAIL; if (!dList_append(list, &ap)) goto FAIL;
printPoint(ap); printf("ap: %p\r\n", ap);
dList_forEachForward(list, n) dList_forEachForward(list, n)
{ {
@ -314,9 +318,45 @@ FAIL:
dList_delete(list); dList_delete(list);
} }
static void test(void) static void usage(void)
{ {
printf("dList test!\r\n"); printf(
"Usage: dList [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("dList version %d.%d.%d\r\n", DLIST_V_MAJOR, DLIST_V_MINOR, DLIST_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_create(); // test_create();
// test_set(); // test_set();
@ -332,6 +372,18 @@ static void test(void)
// test_copy(); // test_copy();
// test_reverse(); // test_reverse();
v_check_unfree(); return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_dList)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_dList(void)
{
command_export("dList", test);
}
init_export_app(test_dList);
#endif

View File

@ -1,8 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_date)
#include <varch/command.h>
#include <varch/date.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "date.h" #include "date.h"
#endif
#if 0 #if 0
static int century_days(int century) static int century_days(int century)
@ -45,8 +51,46 @@ static int thousand3_days(int base)
} }
#endif #endif
static void test(void) static void usage(void)
{ {
printf(
"Usage: date [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("date version %d.%d.%d\r\n", DATE_V_MAJOR, DATE_V_MINOR, DATE_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
printf("month days %d\r\n", date_month_days(2024, 11)); printf("month days %d\r\n", date_month_days(2024, 11));
printf("date_isleap %d\r\n", date_isleap(1582)); printf("date_isleap %d\r\n", date_isleap(1582));
// printf("date_current_days %d\r\n", date_current_days(DATE(1,1,1))); // printf("date_current_days %d\r\n", date_current_days(DATE(1,1,1)));
@ -65,5 +109,19 @@ static void test(void)
date_show(1998,7); date_show(1998,7);
date_show(2024,11); date_show(2024,11);
date_show(2224,11); date_show(2224,11);
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_date)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_date(void)
{
command_export("date", test);
}
init_export_app(test_date);
#endif

View File

@ -1,12 +1,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_deque)
#include <varch/command.h>
#include <varch/deque.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "deque.h" #include "deque.h"
#endif
static void test_deque(void) static void test_base(void)
{ {
deque_t deque = deque(int, 10); deque_t deque = deque(int, 10);
int i = 0; int i = 0;
@ -25,9 +29,60 @@ static void test_deque(void)
_deque(deque); _deque(deque);
} }
static void test(void) static void usage(void)
{ {
test_deque(); printf(
v_check_unfree(); "Usage: deque [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
} }
init_export_app(test);
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("deque version %d.%d.%d\r\n", DEQUE_V_MAJOR, DEQUE_V_MINOR, DEQUE_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
test_base();
return 0;
}
#if defined(TEST_TARGET_deque)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_deque(void)
{
command_export("deque", test);
}
init_export_app(test_deque);
#endif

View File

@ -1,10 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_dict)
#include <varch/command.h>
#include <varch/dict.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
// #include "valloc.h"
#include "dict.h" #include "dict.h"
#endif
#if 0 #if 0
static void dict_print(dict_t dict) static void dict_print(dict_t dict)
@ -70,7 +74,7 @@ static void test_performance(void)
} }
#endif #endif
static void test_dict(void) static void test_base(void)
{ {
dict_t dict = dict(int); dict_t dict = dict(int);
int value; int value;
@ -120,12 +124,62 @@ static void test_dict(void)
_dict(dict); _dict(dict);
} }
static void test(void) static void usage(void)
{ {
test_dict(); printf(
"Usage: dict [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("dict version %d.%d.%d\r\n", DICT_V_MAJOR, DICT_V_MINOR, DICT_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
test_base();
// test_it(); // test_it();
// test_performance(); // test_performance();
// v_check_unfree();
// printf("mem use %d\r\n", v_check_used()); return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_dict)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_dict(void)
{
command_export("dict", test);
}
init_export_app(test_dict);
#endif

View File

@ -1,10 +1,17 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "init.h"
#include "tool.h"
#include "encrypt.h"
#include <stdint.h> #include <stdint.h>
#if defined(TEST_TARGET_encrypt)
#include <varch/command.h>
#include <varch/encrypt.h>
#else
#include "init.h"
#include "command.h"
#include "encrypt.h"
#endif
static void test_des(void) static void test_des(void)
{ {
@ -92,9 +99,61 @@ static void test_des3(void)
printf("\r\n"); printf("\r\n");
} }
static void test(void) static void usage(void)
{ {
printf(
"Usage: encrypt [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("encrypt version %d.%d.%d\r\n", ENCRYPT_V_MAJOR, ENCRYPT_V_MINOR, ENCRYPT_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_des(); // test_des();
test_des3(); test_des3();
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_encrypt)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_encrypt(void)
{
command_export("encrypt", test);
}
init_export_app(test_encrypt);
#endif

View File

@ -1,9 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_filter)
#include <varch/command.h>
#include <varch/filter.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "filter.h" #include "filter.h"
#endif
static void test_median(void) static void test_median(void)
{ {
@ -50,12 +55,62 @@ static void test_kalman(void)
printf("Estimated value: %f\n", estimates[0]); printf("Estimated value: %f\n", estimates[0]);
} }
static void test(void) static void usage(void)
{ {
printf("pid test!\r\n"); printf(
"Usage: filter [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("filter version %d.%d.%d\r\n", FILTER_V_MAJOR, FILTER_V_MINOR, FILTER_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
test_median(); test_median();
// test_average(); // test_average();
// test_kalman(); // test_kalman();
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_filter)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_filter(void)
{
command_export("filter", test);
}
init_export_app(test_filter);
#endif

View File

@ -1,11 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_graph)
#include <varch/command.h>
#include <varch/graph.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "graph.h" #include "graph.h"
#include "arg.h" #endif
#define la(type, value) ((type[1]){value}) #define la(type, value) ((type[1]){value})
@ -364,10 +367,46 @@ static void test_others(void)
graph_delete(graph); graph_delete(graph);
} }
static void test(void) static void usage(void)
{ {
printf("graph test!\r\n"); printf(
"Usage: graph [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("graph version %d.%d.%d\r\n", GRAPH_V_MAJOR, GRAPH_V_MINOR, GRAPH_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_create(); // test_create();
// test_add_vertex(); // test_add_vertex();
// test_add_edge(); // test_add_edge();
@ -379,6 +418,18 @@ static void test(void)
// test_shortest_path(); // test_shortest_path();
test_min_cover(); test_min_cover();
v_check_unfree(); return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_graph)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_graph(void)
{
command_export("graph", test);
}
init_export_app(test_graph);
#endif

View File

@ -3,13 +3,55 @@
#include <string.h> #include <string.h>
#include <float.h> #include <float.h>
#include <math.h> #include <math.h>
#if defined(TEST_TARGET_hash)
#include <varch/command.h>
#include <varch/hash.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "hash.h" #include "hash.h"
#endif
static void test(void) static void usage(void)
{ {
printf(
"Usage: hash [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("hash version %d.%d.%d\r\n", HASH_V_MAJOR, HASH_V_MINOR, HASH_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
printf("hash_bkdr 0x%X\r\n", hash_bkdr("Hello", 5)); printf("hash_bkdr 0x%X\r\n", hash_bkdr("Hello", 5));
printf("hash_ap 0x%X\r\n", hash_ap("Hello", 5)); printf("hash_ap 0x%X\r\n", hash_ap("Hello", 5));
printf("hash_djb 0x%X\r\n", hash_djb("Hello", 5)); printf("hash_djb 0x%X\r\n", hash_djb("Hello", 5));
@ -22,5 +64,19 @@ static void test(void)
printf("hash_bp 0x%X\r\n", hash_bp("Hello", 5)); printf("hash_bp 0x%X\r\n", hash_bp("Hello", 5));
printf("hash_fnv 0x%X\r\n", hash_fnv("Hello", 5)); printf("hash_fnv 0x%X\r\n", hash_fnv("Hello", 5));
printf("hash_jdk6 0x%X\r\n", hash_jdk6("Hello", 5)); printf("hash_jdk6 0x%X\r\n", hash_jdk6("Hello", 5));
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_hash)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_hash(void)
{
command_export("hash", test);
}
init_export_app(test_hash);
#endif

View File

@ -1,10 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_heap)
#include <varch/command.h>
#include <varch/heap.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "heap.h" #include "heap.h"
#endif
static int heap_root_min(void *parent, void *child) static int heap_root_min(void *parent, void *child)
{ {
@ -16,7 +20,7 @@ static int heap_root_max(void *parent, void *child)
if (*(int *)parent > *(int *)child) return 1; if (*(int *)parent > *(int *)child) return 1;
return 0; return 0;
} }
static void test_heap(void) static void test_base(void)
{ {
heap_t h = heap_create(sizeof(int), 11, heap_root_max); heap_t h = heap_create(sizeof(int), 11, heap_root_max);
int i = 0; int i = 0;
@ -41,9 +45,60 @@ static void test_heap(void)
heap_delete(h); heap_delete(h);
} }
static void test(void) static void usage(void)
{ {
test_heap(); printf(
v_check_unfree(); "Usage: heap [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
} }
init_export_app(test);
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("heap version %d.%d.%d\r\n", HEAP_V_MAJOR, HEAP_V_MINOR, HEAP_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
test_base();
return 0;
}
#if defined(TEST_TARGET_heap)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_heap(void)
{
command_export("heap", test);
}
init_export_app(test_heap);
#endif

View File

@ -1,7 +1,12 @@
#include <stdio.h> #include <stdio.h>
#if defined(TEST_TARGET_ini)
#include <varch/command.h>
#include <varch/ini.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "ini.h" #include "ini.h"
#include "valloc.h" #endif
#define READ_FILE "test/file/read.ini" #define READ_FILE "test/file/read.ini"
#define WRITE_FILE "test/file/write.ini" #define WRITE_FILE "test/file/write.ini"
@ -75,12 +80,63 @@ static void test_load(void)
#endif #endif
ini_file_dump(ini, WRITE_FILE); ini_file_dump(ini, WRITE_FILE);
ini_delete(ini); ini_delete(ini);
v_check_unfree();
} }
static void test(void) static void usage(void)
{ {
printf(
"Usage: ini [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("ini version %d.%d.%d\r\n", INI_V_MAJOR, INI_V_MINOR, INI_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_dump(); // test_dump();
test_load(); test_load();
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_ini)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_ini(void)
{
command_export("ini", test);
}
init_export_app(test_ini);
#endif

View File

@ -1,5 +1,12 @@
#include <stdio.h> #include <stdio.h>
#if defined(TEST_TARGET_init)
#include <varch/command.h>
#include <varch/init.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "init.h"
#endif
void test_init_hardware(void) void test_init_hardware(void)
{ {
@ -36,3 +43,59 @@ void test_init_system1(void)
printf("system1 init!\r\n"); printf("system1 init!\r\n");
} }
init_export_system(test_init_system1); init_export_system(test_init_system1);
static void usage(void)
{
printf(
"Usage: init [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("init version %d.%d.%d\r\n", INIT_V_MAJOR, INIT_V_MINOR, INIT_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
return 0;
}
#if defined(TEST_TARGET_init)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_init(void)
{
command_export("init", test);
}
init_export_app(test_init);
#endif

View File

@ -1,31 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <varch/set.h>
int main(int argc, char *argv[])
{
set_t set = set(int);
int i;
for (i = 0; i < 100; i++)
{
set_insert(set, i, &i);
}
printf("size = %d, data size = %d\r\n", set_size(set), set_dsize(set));
i = -100; set_insert(set, i, &i);
i = 1024; set_insert(set, i, &i);
printf("set[6] = %d\r\n", set_at(set, int, 6));
printf("set[-100] = %d\r\n", set_at(set, int, -100));
printf("set[1024] = %d\r\n", set_at(set, int, 1024));
set_at(set, int, 6) = 11111;
printf("set[6] = %d\r\n", set_at(set, int, 6));
_set(set);
}
// gcc ./test/test_install.c -o ./built/bin/app -lvarch
// ./built/bin/app

View File

@ -1,7 +1,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_intl)
#include <varch/command.h>
#include <varch/intl.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "intl.h" #include "intl.h"
#endif
#define INTL_P_DEC 0x01 #define INTL_P_DEC 0x01
#define INTL_P_BIN 0x02 #define INTL_P_BIN 0x02
@ -96,10 +102,62 @@ static void test_calculate(void)
print_intl(intl_dec(b), INTL_P_DEC); print_intl(intl_dec(b), INTL_P_DEC);
} }
static void test(void) static void usage(void)
{ {
printf(
"Usage: intl [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("intl version %d.%d.%d\r\n", INTL_V_MAJOR, INTL_V_MINOR, INTL_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_define(); // test_define();
// test_print(); // test_print();
test_calculate(); test_calculate();
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_intl)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_intl(void)
{
command_export("intl", test);
}
init_export_app(test_intl);
#endif

View File

@ -2,9 +2,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_json)
#include <varch/command.h>
#include <varch/json.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "json.h" #include "json.h"
#include "valloc.h" #endif
#define READ_FILE "test/file/read.json" #define READ_FILE "test/file/read.json"
#define WRITE_FILE "test/file/write.json" #define WRITE_FILE "test/file/write.json"
@ -110,12 +115,61 @@ static void test_write(void)
json_delete(json); json_delete(json);
} }
static void test(void) static void usage(void)
{ {
printf("json test!\r\n"); printf(
test_write(); "Usage: json [opt] [arg]\n"
// test_read(); "\n"
"options:\n"
v_check_unfree(); " -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
} }
init_export_app(test);
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("json version %d.%d.%d\r\n", JSON_V_MAJOR, JSON_V_MINOR, JSON_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_write();
test_read();
return 0;
}
#if defined(TEST_TARGET_json)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_json(void)
{
command_export("json", test);
}
init_export_app(test_json);
#endif

View File

@ -1,11 +1,15 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "init.h"
#include "tool.h"
#include "valloc.h"
#include "kern.h"
#include <sys/time.h> #include <sys/time.h>
#if defined(TEST_TARGET_kern)
#include <varch/command.h>
#include <varch/kern.h>
#else
#include "init.h"
#include "command.h"
#include "kern.h"
#endif
static unsigned int get_msec(void) static unsigned int get_msec(void)
{ {
@ -16,20 +20,59 @@ static unsigned int get_msec(void)
return ms; return ms;
} }
void task1(void) static void task1(void)
{ {
static int count = 0; static int count = 0;
printf("task1 running! %d\r\n", ++count); printf("task1 running! %d\r\n", ++count);
} }
void task2(void) static void task2(void)
{ {
static int count = 0; static int count = 0;
printf("task2 running! %d\r\n", ++count); printf("task2 running! %d\r\n", ++count);
} }
static void test(void) static void usage(void)
{ {
printf(
"Usage: kern [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("kern version %d.%d.%d\r\n", KERN_V_MAJOR, KERN_V_MINOR, KERN_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
#if defined(TEST_TARGET_kern)
if (kern_init(get_msec, 1) == KE_OK) if (kern_init(get_msec, 1) == KE_OK)
{ {
printf("kern init success!\r\n"); printf("kern init success!\r\n");
@ -37,12 +80,30 @@ static void test(void)
else else
{ {
printf("*** kern init fail!\r\n"); printf("*** kern init fail!\r\n");
return; return 0;
} }
// printf("create task %d\r\n", task_create(1000, task1)); printf("create task %d\r\n", task_create(1000, task1));
// printf("create task %d\r\n", task_create(500, task2)); printf("create task %d\r\n", task_create(500, task2));
// kern_schedule(); kern_schedule();
#else
printf("create task %d\r\n", task_create(1000, task1));
printf("create task %d\r\n", task_create(500, task2));
#endif
return 0;
} }
init_export_system(test);
#if defined(TEST_TARGET_kern)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_kern(void)
{
command_export("kern", test);
}
init_export_app(test_kern);
#endif

View File

@ -1,47 +1,43 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_list)
#include <varch/command.h>
#include <varch/list.h>
#include <varch/vector.h>
#include <varch/tool.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "list.h" #include "list.h"
#include "vector.h" #include "vector.h"
#include "tool.h"
#endif
static void test(void) static void test_base(void)
{ {
list_t list = list(int); // 定义并创建int型list list_t list = list(int); // 定义并创建int型list
int i = 0; int i = 0;
unsigned long long start = 0;
unsigned long long stop = 0;
for (i = 0; i < 10000; i++) list_push_back(list, NULL); // 依次插入 0 1 2 for (i = 0; i < 10000; i++) list_push_back(list, NULL); // 依次插入 0 1 2
// 正向遍历用时 // 正向遍历用时
start = reckon_usec();
for (i = 0; i < list_size(list); i++) for (i = 0; i < list_size(list); i++)
{ {
list_at(list, int, i); list_at(list, int, i);
} }
stop = reckon_usec();
printf("use %llu us!\r\n", (stop - start));
// 反向遍历用时 // 反向遍历用时
start = reckon_usec();
for (i = list_size(list) - 1; i >= 0; i--) for (i = list_size(list) - 1; i >= 0; i--)
{ {
list_at(list, int, i); list_at(list, int, i);
} }
stop = reckon_usec();
printf("use %llu us!\r\n", (stop - start));
// 随机访问用时 // 随机访问用时
start = reckon_usec();
for (i = 0; i < list_size(list); i++) for (i = 0; i < list_size(list); i++)
{ {
list_at(list, int, rand()%list_size(list)); list_at(list, int, rand()%list_size(list));
} }
stop = reckon_usec();
printf("use %llu us!\r\n", (stop - start));
printf("size %d\r\n", list_size(list)); printf("size %d\r\n", list_size(list));
@ -52,16 +48,68 @@ static void test(void)
vector_t vt = vector(int, 10000); vector_t vt = vector(int, 10000);
// 正向遍历用时 // 正向遍历用时
start = reckon_usec();
for (i = 0; i < vector_size(vt); i++) for (i = 0; i < vector_size(vt); i++)
{ {
vector_at(vt, int, i); vector_at(vt, int, i);
} }
stop = reckon_usec();
printf("use %llu us!\r\n", (stop - start));
_vector(vt); _vector(vt);
v_check_unfree();
} }
init_export_app(test);
static void usage(void)
{
printf(
"Usage: list [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("list version %d.%d.%d\r\n", LIST_V_MAJOR, LIST_V_MINOR, LIST_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
test_base();
return 0;
}
#if defined(TEST_TARGET_list)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_list(void)
{
command_export("list", test);
}
init_export_app(test_list);
#endif

View File

@ -1,10 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_map)
#include <varch/command.h>
#include <varch/map.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "map.h" #include "map.h"
#endif
static void test_it(void) static void test_it(void)
{ {
@ -32,7 +36,7 @@ static void test_it(void)
_map(map); _map(map);
} }
static void test_map(void) static void test_base(void)
{ {
int value; int value;
map_t map = map(string, int); map_t map = map(string, int);
@ -63,11 +67,63 @@ static void test_float_map(void)
_map(map); _map(map);
} }
static void test(void) static void usage(void)
{ {
test_it(); printf(
// test_map(); "Usage: map [opt] [arg]\n"
// test_float_map(); "\n"
v_check_unfree(); "options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
} }
init_export_app(test);
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("map version %d.%d.%d\r\n", MAP_V_MAJOR, MAP_V_MINOR, MAP_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
test_it();
// test_base();
// test_float_map();
return 0;
}
#if defined(TEST_TARGET_map)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_map(void)
{
command_export("map", test);
}
init_export_app(test_map);
#endif

View File

@ -2,10 +2,17 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include "init.h"
#include "kern.h"
#include "oscp.h"
#include <sys/time.h> #include <sys/time.h>
#if defined(TEST_TARGET_oscp)
#include <varch/command.h>
#include <varch/oscp.h>
#include <varch/kern.h>
#else
#include "init.h"
#include "command.h"
#include "oscp.h"
#include "kern.h"
#endif
int level = 0; int level = 0;
@ -18,12 +25,12 @@ static unsigned int get_msec(void)
return ms; return ms;
} }
void task1(void) static void task1(void)
{ {
oscp_handle(); oscp_handle();
} }
void task2(void) static void task2(void)
{ {
static int count = 0; static int count = 0;
@ -33,8 +40,46 @@ void task2(void)
level = RESOLUTION / 2 * sin((double)count / 10) + RESOLUTION / 2; level = RESOLUTION / 2 * sin((double)count / 10) + RESOLUTION / 2;
} }
static void test(void) static void usage(void)
{ {
printf(
"Usage: oscp [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("oscp version %d.%d.%d\r\n", OSCP_V_MAJOR, OSCP_V_MINOR, OSCP_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
if (kern_init(get_msec, 1) == KE_OK) if (kern_init(get_msec, 1) == KE_OK)
{ {
printf("kern init success!\r\n"); printf("kern init success!\r\n");
@ -42,7 +87,7 @@ static void test(void)
else else
{ {
printf("*** kern init fail!\r\n"); printf("*** kern init fail!\r\n");
return; return 0;
} }
printf("create task %d\r\n", task_create(5, task1)); printf("create task %d\r\n", task_create(5, task1));
@ -52,5 +97,19 @@ static void test(void)
oscp_set_monitor(&level); oscp_set_monitor(&level);
kern_schedule(); kern_schedule();
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_oscp)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_oscp(void)
{
command_export("oscp", test);
}
init_export_app(test_oscp);
#endif

View File

@ -1,9 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_pid)
#include <varch/command.h>
#include <varch/pid.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "pid.h" #include "pid.h"
#endif
static void test_sim(void) static void test_sim(void)
{ {
@ -27,10 +32,60 @@ static void test_sim(void)
} }
} }
static void test(void) static void usage(void)
{ {
printf("pid test!\r\n"); printf(
"Usage: pid [opt] [arg]\n"
test_sim(); "\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
} }
init_export_app(test);
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("pid version %d.%d.%d\r\n", PID_V_MAJOR, PID_V_MINOR, PID_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
test_sim();
return 0;
}
#if defined(TEST_TARGET_pid)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_pid(void)
{
command_export("pid", test);
}
init_export_app(test_pid);
#endif

View File

@ -1,32 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "init.h"
#include "tool.h"
#include "valloc.h"
#include <pthread.h>
#include <semaphore.h>
sem_t s;
static void *thread_entry(void *param)
{
long thread_id = (long)param;
for (;;)
{
sem_wait(&s);
printf("in\r\n");
}
return NULL;
};
static void test(void)
{
pthread_t t;
pthread_create(&t, NULL, thread_entry, NULL);
printf("pthread\r\n");
sem_post(&s);
}
init_export_app(test);

View File

@ -1,12 +1,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_queue)
#include <varch/command.h>
#include <varch/queue.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "queue.h" #include "queue.h"
#endif
static void test_queue(void) static void test_base(void)
{ {
queue_t queue = queue(int, 10); queue_t queue = queue(int, 10);
int i = 0; int i = 0;
@ -26,9 +30,62 @@ static void test_queue(void)
_queue(queue); _queue(queue);
} }
static void test(void) static void usage(void)
{ {
test_queue(); printf(
v_check_unfree(); "Usage: queue [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
} }
init_export_app(test);
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("queue version %d.%d.%d\r\n", QUEUE_V_MAJOR, QUEUE_V_MINOR, QUEUE_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
test_base();
return 0;
}
#if defined(TEST_TARGET_queue)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_queue(void)
{
command_export("queue", test);
}
init_export_app(test_queue);
#endif

View File

@ -1,10 +1,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_ramt)
#include <varch/command.h>
#include <varch/ramt.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "ramt.h" #include "ramt.h"
#include "kern.h" #include "kern.h"
#endif
#define TASK_PERIOD 5 // ms #define TASK_PERIOD 5 // ms
@ -25,11 +31,55 @@ static void test_task(void)
} }
} }
static void test_ramt(void) static void usage(void)
{ {
task_t task; printf(
"Usage: ramt [opt] [arg]\n"
printf("ramt test!\r\n"); "\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
int period = 1000; // ms
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "p:hv");
if (opt == -1) break;
switch (opt)
{
case 'p' :
period = atoi(command_optarg);
break;
case 'v' :
printf("ramt version %d.%d.%d\r\n", RAMT_V_MAJOR, RAMT_V_MINOR, RAMT_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
if (1 == command_optind) // no opt
{
test_task();
return 0;
}
ramt_object.base = (void *)buffer; ramt_object.base = (void *)buffer;
ramt_object.size = sizeof(buffer); ramt_object.size = sizeof(buffer);
@ -37,7 +87,28 @@ static void test_ramt(void)
ramt_start(&ramt_object, RAMT_MODE_NORMAL, 0xFFFFFFFF); ramt_start(&ramt_object, RAMT_MODE_NORMAL, 0xFFFFFFFF);
task = task_create(TASK_PERIOD, test_task); #if defined(TEST_TARGET_ramt)
printf("task <%d>\r\n", task); while (1)
{
test_task();
usleep(1000 * period);
}
#else
printf("create task %d\r\n", task_create(TASK_PERIOD, test_task));
#endif
return 0;
}
#if defined(TEST_TARGET_ramt)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_ramt(void)
{
command_export("ramt", test);
} }
init_export_app(test_ramt); init_export_app(test_ramt);
#endif

View File

@ -1,25 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "init.h"
#include "tool.h"
#include "valloc.h"
#include "rbtree.h"
static void print_int(tree_t tree)
{
if (tree_data(tree)) printf("%d", *(int *)tree_data(tree));
}
static void test(void)
{
printf("rbtree test\r\n");
v_check_unfree();
// printf("used %d\r\n", v_check_used());
}
init_export_app(test);

View File

@ -1,10 +1,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_sList)
#include <varch/command.h>
#include <varch/sList.h>
#include <varch/tool.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "sList.h" #include "sList.h"
#include "tool.h"
#endif
static void test_create(void); static void test_create(void);
static void test_set(void); static void test_set(void);
@ -319,9 +325,45 @@ FAIL:
sList_delete(list); sList_delete(list);
} }
static void test(void) static void usage(void)
{ {
printf("sList test!\r\n"); printf(
"Usage: sList [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("sList version %d.%d.%d\r\n", SLIST_V_MAJOR, SLIST_V_MINOR, SLIST_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_create(); // test_create();
test_set(); test_set();
@ -337,6 +379,18 @@ static void test(void)
// test_copy(); // test_copy();
// test_reverse(); // test_reverse();
v_check_unfree(); return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_sList)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_sList(void)
{
command_export("sList", test);
}
init_export_app(test_sList);
#endif

View File

@ -1,9 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_search)
#include <varch/command.h>
#include <varch/search.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "search.h" #include "search.h"
#endif
static void* int_array_addr(void *array, int index) static void* int_array_addr(void *array, int index)
{ {
@ -57,11 +62,61 @@ static void test_binary(void)
target = -9, printf("search %d, result %d\r\n", target, search_binary(array, 0, sizeof(array) / sizeof(array[0]) - 1, &target, &ops)); target = -9, printf("search %d, result %d\r\n", target, search_binary(array, 0, sizeof(array) / sizeof(array[0]) - 1, &target, &ops));
} }
static void test(void) static void usage(void)
{ {
printf("search test!\r\n"); printf(
"Usage: search [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("search version %d.%d.%d\r\n", SEARCH_V_MAJOR, SEARCH_V_MINOR, SEARCH_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_linear(); // test_linear();
test_binary(); test_binary();
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_search)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_search(void)
{
command_export("search", test);
}
init_export_app(test_search);
#endif

View File

@ -1,10 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_set)
#include <varch/command.h>
#include <varch/set.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "set.h" #include "set.h"
#endif
static void test_it(void) static void test_it(void)
{ {
@ -32,7 +36,7 @@ static void test_it(void)
_set(set); _set(set);
} }
static void test_set(void) static void test_base(void)
{ {
set_t set = set(int); set_t set = set(int);
int i; int i;
@ -56,10 +60,61 @@ static void test_set(void)
_set(set); _set(set);
} }
static void test(void) static void usage(void)
{ {
// test_set(); printf(
test_it(); "Usage: set [opt] [arg]\n"
v_check_unfree(); "\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
} }
init_export_app(test);
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("set version %d.%d.%d\r\n", SET_V_MAJOR, SET_V_MINOR, SET_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_base();
test_it();
return 0;
}
#if defined(TEST_TARGET_set)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_set(void)
{
command_export("set", test);
}
init_export_app(test_set);
#endif

View File

@ -1,11 +1,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_sort)
#include <varch/command.h>
#include <varch/sort.h>
#include <varch/list.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "sort.h" #include "sort.h"
#include "list.h" #include "list.h"
#endif
static void test_basic_usage(void) static void test_basic_usage(void)
{ {
@ -208,12 +213,65 @@ static void test_struct(void)
printf("---------------------------------\r\n"); printf("---------------------------------\r\n");
} }
static void test(void) static void usage(void)
{ {
printf(
"Usage: sort [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("sort version %d.%d.%d\r\n", SORT_V_MAJOR, SORT_V_MINOR, SORT_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_basic_usage(); // test_basic_usage();
// test_interval(); // test_interval();
// test_list_sort(); // test_list_sort();
test_struct(); test_struct();
return 0;
} }
init_export_app(test); #if defined(TEST_TARGET_sort)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_sort(void)
{
command_export("sort", test);
}
init_export_app(test_sort);
#endif

View File

@ -1,12 +1,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_stack)
#include <varch/command.h>
#include <varch/stack.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "stack.h" #include "stack.h"
#endif
static void test_stack(void) static void test_base(void)
{ {
stack_t stack = stack(int, 10); stack_t stack = stack(int, 10);
int i = 0; int i = 0;
@ -25,9 +29,61 @@ static void test_stack(void)
_stack(stack); _stack(stack);
} }
static void test(void) static void usage(void)
{ {
test_stack(); printf(
v_check_unfree(); "Usage: stack [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
} }
init_export_app(test);
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("stack version %d.%d.%d\r\n", STACK_V_MAJOR, STACK_V_MINOR, STACK_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
test_base();
return 0;
}
#if defined(TEST_TARGET_stack)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_stack(void)
{
command_export("stack", test);
}
init_export_app(test_stack);
#endif

View File

@ -1,17 +1,73 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_str)
#include <varch/command.h>
#include <varch/str.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "str.h" #include "str.h"
#endif
static void test(void) static void usage(void)
{ {
printf(
"Usage: str [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("str version %d.%d.%d\r\n", STR_V_MAJOR, STR_V_MINOR, STR_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
str_t s = str("0123456789"); str_t s = str("0123456789");
str_replace(s, 9, 10, "AAAAAAAAAA"); str_replace(s, 9, 10, "AAAAAAAAAA");
printf("len %d, %d\r\n", str_length(s), str_capacity(s)); printf("len %d, %d\r\n", str_length(s), str_capacity(s));
printf("%s\r\n", _S(s)); printf("%s\r\n", _S(s));
_str(s); _str(s);
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_str)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_str(void)
{
command_export("str", test);
}
init_export_app(test_str);
#endif

View File

@ -1,7 +1,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_tool)
#include <varch/command.h>
#include <varch/tool.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "tool.h" #include "tool.h"
#endif
static void test_GetStringHex(void) static void test_GetStringHex(void)
{ {
@ -48,10 +54,63 @@ static void test_print(void)
printString(s); printString(s);
} }
static void test(void) static void usage(void)
{ {
printf(
"Usage: tool [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("tool version %d.%d.%d\r\n", TOOL_V_MAJOR, TOOL_V_MINOR, TOOL_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_GetStringHex(); // test_GetStringHex();
// test_ASSERT(); // test_ASSERT();
test_print(); test_print();
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_tool)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_tool(void)
{
command_export("tool", test);
}
init_export_app(test_tool);
#endif

View File

@ -1,10 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_tree)
#include <varch/command.h>
#include <varch/tree.h>
#else
#include "init.h" #include "init.h"
#include "tool.h" #include "command.h"
#include "valloc.h"
#include "tree.h" #include "tree.h"
#endif
static void print_int(tree_t tree) static void print_int(tree_t tree)
{ {
@ -189,8 +193,6 @@ static tree_t bitree_gen(int depth)
return tree; return tree;
} }
static void test_bitree(void) static void test_bitree(void)
{ {
tree_t tree = bitree_gen(5); tree_t tree = bitree_gen(5);
@ -199,16 +201,63 @@ static void test_bitree(void)
tree_delete(tree, NULL); tree_delete(tree, NULL);
} }
static void test(void) static void usage(void)
{ {
printf("tree test\r\n"); printf(
"Usage: tree [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("tree version %d.%d.%d\r\n", TREE_V_MAJOR, TREE_V_MINOR, TREE_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
// test_create(); // test_create();
test_dir(); test_dir();
// test_ini(); // test_ini();
// test_bitree(); // test_bitree();
v_check_unfree(); return 0;
// printf("used %d\r\n", v_check_used());
} }
init_export_app(test);
#if defined(TEST_TARGET_tree)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_tree(void)
{
command_export("tree", test);
}
init_export_app(test_tree);
#endif

View File

@ -1,8 +1,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_txls)
#include <varch/command.h>
#include <varch/txls.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "txls.h" #include "txls.h"
#include "valloc.h" #endif
#define READ_FILE "test/file/read.md" #define READ_FILE "test/file/read.md"
#define WRITE_FILE "test/file/write.md" #define WRITE_FILE "test/file/write.md"
@ -21,11 +26,11 @@ void txls_preview(txls_t txls)
static void test_read(void) static void test_read(void)
{ {
txls_t x = NULL; // 定义txls对象习惯初始化为NULL txls_t x = NULL; // Define the txls object, initialized to NULL as usual
/* 加载txls文件 */ /* Load the txls file */
x = txls_file_load(READ_FILE); x = txls_file_load(READ_FILE);
if (!x) // 加载失败,定位错误 if (!x) // Loading failed, locating error
{ {
int line, type; int line, type;
type = txls_error_info(&line); type = txls_error_info(&line);
@ -33,7 +38,7 @@ static void test_read(void)
return; return;
} }
/* 遍历表头,定位所在列 */ /* Iterate over the header to locate the column*/
int col = 0; int col = 0;
for (col = 1; col <= txls_col(x); col++) for (col = 1; col <= txls_col(x); col++)
{ {
@ -42,13 +47,13 @@ static void test_read(void)
break; break;
} }
} }
if (col > txls_col(x)) // 没有查找到 if (col > txls_col(x)) // Not found
{ {
printf("Lookup failed\r\n"); printf("Lookup failed\r\n");
return; return;
} }
/* 打印信息 */ /* print info */
printf("name: %s, age=%s, gender: %s, height=%s, weight=%s, email:%s\r\n", printf("name: %s, age=%s, gender: %s, height=%s, weight=%s, email:%s\r\n",
txls_get_text(x, col, 0), txls_get_text(x, col, 0),
txls_get_text(x, col, 1), txls_get_text(x, col, 1),
@ -62,32 +67,32 @@ static void test_read(void)
static void test_write(void) static void test_write(void)
{ {
txls_t x = NULL; // 定义txls对象习惯初始化为NULL txls_t x = NULL; // Define the txls object, initialized to NULL as usual
x = txls_create(4, 5); // 创建4x5的表格 x = txls_create(4, 5); // Create a 4x5 txls
if (!x) if (!x)
{ {
return; return;
} }
/* 设置表头,第一列留空 */ /* Sets the header of the table, leaving the first column blank */
txls_set_head(x, 2, "Zhang San"); txls_set_head(x, 2, "Zhang San");
txls_set_head(x, 3, "Li Si"); txls_set_head(x, 3, "Li Si");
txls_set_head(x, 4, "Wang Wu"); txls_set_head(x, 4, "Wang Wu");
/* 设置对齐方式 */ /* Set the alignment */
txls_set_align(x, 2, TXLS_ALIGN_LEFT); txls_set_align(x, 2, TXLS_ALIGN_LEFT);
txls_set_align(x, 3, TXLS_ALIGN_CENTER); txls_set_align(x, 3, TXLS_ALIGN_CENTER);
txls_set_align(x, 4, TXLS_ALIGN_RIGHT); txls_set_align(x, 4, TXLS_ALIGN_RIGHT);
/* 第一列作为信息类别 */ /* The first column serves as the information category */
txls_set_text(x, 1, 1, "age"); txls_set_text(x, 1, 1, "age");
txls_set_text(x, 1, 2, "gender"); txls_set_text(x, 1, 2, "gender");
txls_set_text(x, 1, 3, "height"); txls_set_text(x, 1, 3, "height");
txls_set_text(x, 1, 4, "weight"); txls_set_text(x, 1, 4, "weight");
txls_set_text(x, 1, 5, "email"); txls_set_text(x, 1, 5, "email");
/* 写入每个人信息 */ /* Write per-person information */
// Zhang San // Zhang San
txls_set_text(x, 2, 1, "18"); txls_set_text(x, 2, 1, "18");
txls_set_text(x, 2, 2, "man"); txls_set_text(x, 2, 2, "man");
@ -112,11 +117,70 @@ static void test_write(void)
txls_delete(x); txls_delete(x);
} }
static void test(void) static void usage(void)
{ {
// test_write(); printf(
test_read(); "Usage: txls [opt] [arg]\n"
"\n"
// v_check_unfree(); "options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
} }
init_export_app(test);
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("txls version %d.%d.%d\r\n", TXLS_V_MAJOR, TXLS_V_MINOR, TXLS_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
for (int index = command_optind; index < argc; index++)
{
if (!strcmp(argv[index], "read"))
{
test_read();
}
else if (!strcmp(argv[index], "write"))
{
test_write();
}
}
return 0;
}
#if defined(TEST_TARGET_txls)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_txls(void)
{
command_export("txls", test);
}
init_export_app(test_txls);
#endif

View File

@ -1,9 +1,16 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h>
#if defined(TEST_TARGET_unitt)
#include <varch/command.h>
#include <varch/unitt.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "unitt.h" #include "unitt.h"
#include "kern.h" #include "kern.h"
#endif
#if 0 #if 0
#ifdef _WIN32 #ifdef _WIN32
@ -19,8 +26,8 @@ void get_memory_usage(int* resident_set_size, int* virtual_memory_size)
#ifdef _WIN32 #ifdef _WIN32
PROCESS_MEMORY_COUNTERS pmc; PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) { if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) {
*resident_set_size = pmc.WorkingSetSize / 1024; // 转换为KB *resident_set_size = pmc.WorkingSetSize / 1024; // Converting to KB
*virtual_memory_size = pmc.PagefileUsage / 1024; // 转换为KB *virtual_memory_size = pmc.PagefileUsage / 1024; // Converting to KB
} else { } else {
*resident_set_size = 0; *resident_set_size = 0;
*virtual_memory_size = 0; *virtual_memory_size = 0;
@ -49,114 +56,97 @@ uint64_t unitt_clock(void)
return us; return us;
} }
// 计算两个整数的和 int unitt_add(int a, int b)
int unit_add(int a, int b)
{ {
return a + b; return a + b;
} }
// 计算两个整数的差 int unitt_subtract(int a, int b)
int unit_subtract(int a, int b)
{ {
return a - b; return a - b;
} }
// 计算两个整数的乘积 int unitt_multiply(int a, int b)
int unit_multiply(int a, int b)
{ {
return a * b; return a * b;
} }
// 计算两个整数的商 float unitt_divide(int a, int b)
float unit_divide(int a, int b)
{ {
if (b == 0) if (b == 0)
{ {
return 0; // 简单处理,真实应用中应更严格处理 return 0;
} }
return (float)a / (float)b; return (float)a / (float)b;
} }
// 测试前的初始化函数
int setup() int setup()
{ {
// 初始化代码(如果需要)
return 0; return 0;
} }
// 测试后的清理函数
int teardown() int teardown()
{ {
// 清理代码(如果需要)
return 0; return 0;
} }
// 随机输入生成函数
int random_input() int random_input()
{ {
return rand() % 100; // 生成0到99之间的随机整数 return rand() % 100;
} }
// 测试加法函数,使用随机输入
int test_add() int test_add()
{ {
// 进行10次随机测试
for (int i = 0; i < SINGLE_TCOUNT; i++) for (int i = 0; i < SINGLE_TCOUNT; i++)
{ {
int a = random_input(); int a = random_input();
int b = random_input(); int b = random_input();
if (UNITT_E_FAIL == unitt_det_equal(unit_add(a, b), a + b, "Random addition failed")) return UNITT_E_FAIL; if (UNITT_E_FAIL == unitt_det_equal(unitt_add(a, b), a + b, "Random addition failed")) return UNITT_E_FAIL;
} }
return UNITT_E_OK; return UNITT_E_OK;
} }
// 测试减法函数,使用随机输入
int test_subtract() int test_subtract()
{ {
// 进行10次随机测试
for (int i = 0; i < SINGLE_TCOUNT; i++) for (int i = 0; i < SINGLE_TCOUNT; i++)
{ {
int a = random_input(); int a = random_input();
int b = random_input(); int b = random_input();
if (UNITT_E_FAIL == unitt_det_equal(unit_subtract(a, b), a - b, "Random subtraction failed")) return UNITT_E_FAIL; if (UNITT_E_FAIL == unitt_det_equal(unitt_subtract(a, b), a - b, "Random subtraction failed")) return UNITT_E_FAIL;
} }
return UNITT_E_OK; return UNITT_E_OK;
} }
// 测试乘法函数,使用随机输入
int test_multiply() int test_multiply()
{ {
// 进行10次随机测试
for (int i = 0; i < SINGLE_TCOUNT; i++) for (int i = 0; i < SINGLE_TCOUNT; i++)
{ {
int a = random_input(); int a = random_input();
int b = random_input(); int b = random_input();
if (UNITT_E_FAIL == unitt_det_equal(unit_multiply(a, b), a * b, "Random multiplication failed")) return UNITT_E_FAIL; if (UNITT_E_FAIL == unitt_det_equal(unitt_multiply(a, b), a * b, "Random multiplication failed")) return UNITT_E_FAIL;
} }
return UNITT_E_OK; return UNITT_E_OK;
} }
// 测试除法函数,使用随机输入
int test_divide() int test_divide()
{ {
// 进行10次随机测试
for (int i = 0; i < SINGLE_TCOUNT; i++) for (int i = 0; i < SINGLE_TCOUNT; i++)
{ {
int a = random_input(); int a = random_input();
int b = random_input(); int b = random_input();
if (b != 0) if (b != 0)
{ {
if (UNITT_E_FAIL == unitt_det_float(unit_divide(a, b), (float)a / (float)b, 0.00001, "Random division failed")) return UNITT_E_FAIL; if (UNITT_E_FAIL == unitt_det_float(unitt_divide(a, b), (float)a / (float)b, 0.00001, "Random division failed")) return UNITT_E_FAIL;
} }
} }
return UNITT_E_OK; return UNITT_E_OK;
} }
void unit_main() void unitt_main()
{ {
static UNITT_TCASE math_tests[] = { static UNITT_TCASE math_tests[] = {
UNITT_TCASE(test_add), UNITT_TCASE(test_add),
@ -172,11 +162,78 @@ void unit_main()
UNITT_EXE(suites); UNITT_EXE(suites);
} }
static void test(void) static void usage(void)
{ {
srand((unsigned int)time(NULL)); // 初始化随机数种子 printf(
"Usage: unitt [opt] [arg]\n"
// unit_main(); "\n"
printf("create task %d\r\n", task_create(1000, unit_main)); "options:\n"
" -p <period> Test period, unit ms\n"
" -h Print help\n"
" -v Print version\n"
"\n"
);
} }
init_export_app(test);
static int test(int argc, char *argv[])
{
int period = 1000; // ms
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "p:hv");
if (opt == -1) break;
switch (opt)
{
case 'p' :
period = atoi(command_optarg);
break;
case 'v' :
printf("unitt version %d.%d.%d\r\n", UNITT_V_MAJOR, UNITT_V_MINOR, UNITT_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
if (1 == command_optind) // no opt
{
unitt_main();
return 0;
}
srand((unsigned int)time(NULL));
#if defined(TEST_TARGET_unitt)
while (1)
{
unitt_main();
usleep(1000 * period);
}
#else
printf("create task %d\r\n", task_create(period, unitt_main));
#endif
return 0;
}
#if defined(TEST_TARGET_unitt)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_unitt(void)
{
command_export("unitt", test);
}
init_export_app(test_unitt);
#endif

View File

@ -1,10 +1,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_valloc)
#include <varch/command.h>
#include <varch/valloc.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "valloc.h" #include "valloc.h"
#endif
static void test(void) static void test_base(void)
{ {
void* p = NULL; void* p = NULL;
printf("malloc %p\r\n", malloc(0)); printf("malloc %p\r\n", malloc(0));
@ -19,4 +25,66 @@ static void test(void)
printf("count = %d\r\n", v_check_count()); printf("count = %d\r\n", v_check_count());
printf("used = %d\r\n", v_check_used()); printf("used = %d\r\n", v_check_used());
} }
init_export_app(test);
static void usage(void)
{
printf(
"Usage: valloc [opt] [arg]\n"
"\n"
"options:\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <base> Test default read function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("valloc version %d.%d.%d\r\n", VALLOC_V_MAJOR, VALLOC_V_MINOR, VALLOC_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
for (int index = command_optind; index < argc; index++)
{
if (!strcmp(argv[index], "base"))
{
test_base();
}
}
return 0;
}
#if defined(TEST_TARGET_valloc)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_valloc(void)
{
command_export("valloc", test);
}
init_export_app(test_valloc);
#endif

View File

@ -1,33 +1,66 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_vector)
#include <varch/command.h>
#include <varch/vector.h>
#else
#include "init.h" #include "init.h"
#include "valloc.h" #include "command.h"
#include "vector.h" #include "vector.h"
#endif
#define up_multiple(x, mul) ((x)+((mul)-((x)-1)%(mul))-1) /* get the smallest 'mul' multiple larger than 'x' */ static void usage(void)
static int gradient_capacity(int size)
{ {
int capacity = 1; printf(
if (size <= 1) return 1; "Usage: vector [opt] [arg]\n"
while (capacity < size) capacity <<= 1; "\n"
capacity >>= 1; "options:\n"
if (capacity < 4) capacity = capacity << 1; " -h Print help\n"
else if (capacity < 16) capacity = up_multiple(size, capacity >> 1); " -v Print version\n"
else if (capacity < 256) capacity = up_multiple(size, capacity >> 2); "\n"
else capacity = up_multiple(size, 64); "argument:\n"
return capacity; " <read> Test default read function\n"
" <write> Test default write function\n"
);
} }
static void test(void) static int test(int argc, char *argv[])
{ {
int size = 0, capacity = 0; /* reset getopt */
for (size = 1; size < 1024; ) command_opt_init();
while (1)
{ {
capacity = gradient_capacity(size); int opt = command_getopt(argc, argv, "hv");
printf("+%d\t%d\r\n", capacity - size + 1, capacity); if (opt == -1) break;
size = capacity + 1;
switch (opt)
{
case 'v' :
printf("vector version %d.%d.%d\r\n", VECTOR_V_MAJOR, VECTOR_V_MINOR, VECTOR_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
} }
v_check_unfree(); return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_vector)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_vector(void)
{
command_export("vector", test);
}
init_export_app(test_vector);
#endif

View File

@ -1,13 +1,23 @@
#include "vlog.h"
#include "init.h"
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#if defined(TEST_TARGET_vlog)
#include <varch/command.h>
#include <varch/vlog.h>
#else
#include "init.h"
#include "command.h"
#include "vlog.h"
#endif
#define DEFAULT_OFFLINEFILE "./test/file/log.txt"
static void vlog_callback(char *buf, int len) static void vlog_callback(char *buf, int len)
{ {
printf("vlog_callback[%d]: %s", len, buf); printf("vlog_callback[%d]: %s", len, buf);
} }
static void test_vlog(void) static void test_base(void)
{ {
vlog(VLOG_CHANNEL_0, "[VLOG_CHANNEL_0] vlog!\r\n"); vlog(VLOG_CHANNEL_0, "[VLOG_CHANNEL_0] vlog!\r\n");
vlog(VLOG_CHANNEL_1, "[VLOG_CHANNEL_1] vlog!\r\n"); vlog(VLOG_CHANNEL_1, "[VLOG_CHANNEL_1] vlog!\r\n");
@ -26,7 +36,7 @@ static void test_channel(void)
static void test_offline(void) static void test_offline(void)
{ {
vlog_set_offline(VLOG_CHANNEL_0, "./test/file/log.txt"); vlog_set_offline(VLOG_CHANNEL_0, DEFAULT_OFFLINEFILE);
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
@ -36,11 +46,103 @@ static void test_offline(void)
vlog_set_offline(VLOG_CHANNEL_0, NULL); vlog_set_offline(VLOG_CHANNEL_0, NULL);
} }
static void test(void) static void usage(void)
{ {
// vlog_set_func(vlog_callback); printf(
// test_vlog(); "Usage: vlog [opt] [arg]\n"
// test_channel(); "\n"
test_offline(); "options:\n"
" -c [<channel>] Select the output channel and select by bit, channel 0 by default\n"
" 1: channel 0\n"
" 2: channel 1\n"
" 4: channel 2\n"
" 8: channel 3\n"
" ...\n"
" -f [<offline file>] Select the offline out file name, \"./test/file/log.txt\" by default\n"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <base> Test base function\n"
" <channel> Test channel function\n"
" <offline> Test offline function\n"
);
} }
init_export_app(test);
static int test(int argc, char *argv[])
{
char *logfile = DEFAULT_OFFLINEFILE;
vlogChnType chn = VLOG_CHANNEL_0;
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "c::f::hv");
if (opt == -1) break;
switch (opt)
{
case 'c' :
chn = atoi(command_optarg);
break;
case 'f' :
if (command_optarg)
{
logfile = command_optarg;
}
else
{
logfile = DEFAULT_OFFLINEFILE;
}
break;
case 'v' :
printf("vlog version %d.%d.%d\r\n", VLOG_V_MAJOR, VLOG_V_MINOR, VLOG_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
if (logfile) vlog_set_offline(chn, logfile);
vlog(chn, "Hello vlog!\r\n");
if (logfile) vlog_set_offline(chn, NULL);
// vlog_set_func(vlog_callback);
for (int index = command_optind; index < argc; index++)
{
if (!strcmp(argv[index], "base"))
{
test_base();
}
else if (!strcmp(argv[index], "channel"))
{
test_channel();
}
else if (!strcmp(argv[index], "offline"))
{
test_offline();
}
}
return 0;
}
#if defined(TEST_TARGET_vlog)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_vlog(void)
{
command_export("vlog", test);
}
init_export_app(test_vlog);
#endif

View File

@ -1,10 +1,16 @@
#if defined(TEST_TARGET_vstd)
#include <varch/vstdlib.h>
#include <varch/vmem.h>
#else
#include "init.h" #include "init.h"
#include "vstdlib.h" #include "vstdlib.h"
#include "vmem.h" #include "vmem.h"
#endif
int printf (const char *__format, ...); extern int printf (const char *__format, ...);
static void test(void) static int test(int argc, char *argv[])
{ {
uint8_t *p; uint8_t *p;
@ -14,7 +20,7 @@ static void test(void)
if (!p) if (!p)
{ {
printf("malloc fail!\r\n"); printf("malloc fail!\r\n");
return; return 0;
} }
else else
{ {
@ -26,5 +32,19 @@ static void test(void)
v_free(p); v_free(p);
printf("used %d\r\n", vmem_used()); printf("used %d\r\n", vmem_used());
return 0;
} }
init_export_app(test);
#if defined(TEST_TARGET_vstd)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_vstd(void)
{
command_export("vstd", test);
}
init_export_app(test_vstd);
#endif

View File

@ -1,7 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(TEST_TARGET_xml)
#include <varch/command.h>
#include <varch/xml.h>
#else
#include "init.h" #include "init.h"
#include "command.h"
#include "xml.h" #include "xml.h"
#endif
#define READ_FILE "test/file/read.xml" #define READ_FILE "test/file/read.xml"
#define WRITE_FILE "test/file/write.xml" #define WRITE_FILE "test/file/write.xml"
@ -55,12 +62,70 @@ static void test_write(void)
xml_delete(root); xml_delete(root);
} }
static void test(void) static void usage(void)
{ {
printf("xml test!\r\n"); printf(
test_write(); "Usage: xml [opt] [arg]\n"
// test_read(); "\n"
"options:\n"
v_check_unfree(); " -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
} }
init_export_app(test);
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
case 'v' :
printf("xml version %d.%d.%d\r\n", XML_V_MAJOR, XML_V_MINOR, XML_V_PATCH);
return 0;
case '?':
printf("Unknown option `%c`\r\n", command_optopt);
return -1;
case 'h' :
default:
usage();
return 0;
}
}
for (int index = command_optind; index < argc; index++)
{
if (!strcmp(argv[index], "read"))
{
test_read();
}
else if (!strcmp(argv[index], "write"))
{
test_write();
}
}
return 0;
}
#if defined(TEST_TARGET_xml)
int main(int argc, char *argv[])
{
return test(argc, argv);
}
#else
void test_xml(void)
{
command_export("xml", test);
}
init_export_app(test_xml);
#endif