This commit is contained in:
pikastech 2023-05-22 17:58:06 +08:00
parent 277f135e87
commit 974a3619f7
19 changed files with 0 additions and 11188 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,101 +0,0 @@
#include "test_common.h"
TEST_START
TEST(arg_test, cache_) {
Arg* arg1 = arg_newInt(1);
arg_deinit(arg1);
Arg* arg2 = arg_newInt(2);
int val = arg_getInt(arg2);
EXPECT_EQ(val, 2);
arg_deinit(arg2);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(arg_test, int_) {
Arg* arg = New_arg(NULL);
arg = arg_setInt(arg, "test", 1);
int a = arg_getInt(arg);
EXPECT_EQ(a, 1);
arg_deinit(arg);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(arg_test, bool_) {
Arg* arg = New_arg(NULL);
arg = arg_setBool(arg, "test", PIKA_TRUE);
PIKA_BOOL a = arg_getBool(arg);
EXPECT_EQ(a, PIKA_TRUE);
arg_deinit(arg);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(arg_test, float_) {
Arg* arg = New_arg(NULL);
arg = arg_setFloat(arg, "test", 1.01);
float a = arg_getFloat(arg);
EXPECT_EQ(a, (float)1.01);
arg_deinit(arg);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(arg_test, str_) {
Arg* arg = New_arg(NULL);
arg = arg_setStr(arg, "test", "test str");
char* a = arg_getStr(arg);
EXPECT_EQ(strEqu(a, "test str"), 1);
arg_deinit(arg);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(arg_test, ptr) {
Arg* arg = New_arg(NULL);
int a = 1;
arg = arg_setPtr(arg, "test", ARG_TYPE_POINTER, &a);
int* pa = (int*)arg_getPtr(arg);
EXPECT_EQ(*pa, 1);
arg_deinit(arg);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(arg_test, name) {
Arg* arg = New_arg(NULL);
arg = arg_setName(arg, "test");
Hash nameHash = arg_getNameHash(arg);
EXPECT_EQ(hash_time33("test"), nameHash);
arg_deinit(arg);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(arg_test, type) {
Arg* arg = arg_newInt(1);
pika_assert(NULL != arg);
arg_setType(arg, ARG_TYPE_NONE);
ArgType type = arg_getType(arg);
EXPECT_EQ(ARG_TYPE_NONE, type);
arg_deinit(arg);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(arg_test, null) {
Arg* arg = New_arg(NULL);
arg = arg_setNone(arg);
ArgType type = arg_getType(arg);
EXPECT_EQ(ARG_TYPE_NONE, type);
arg_deinit(arg);
EXPECT_EQ(pikaMemNow(), 0);
}
Arg* arg_strAppend(Arg* arg_in, char* str_to_append);
TEST(arg_test, append) {
Arg* arg = arg_newStr("test");
arg = arg_strAppend(arg, "hello");
EXPECT_STREQ(arg_getStr(arg), "testhello");
arg_deinit(arg);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(arg_test, hash_1) {
EXPECT_EQ(hash_time33("print"), 271190290);
}
TEST_END

View File

@ -1,281 +0,0 @@
#include "test_common.h"
TEST_START
static int mem;
TEST(args, test1) {
mem = pikaMemNow();
Args* args = New_args(NULL);
args_setInt(args, "a", 1);
int a = args_getInt(args, "a");
EXPECT_EQ(a, 1);
args_deinit(args);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, test4) {
int32_t testint = 12333;
Args* args = New_args(NULL);
args_setInt(args, "testint", testint);
EXPECT_EQ(12333, args_getInt(args, "testint"));
args_deinit(args);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, test2) {
Args* args = New_args(NULL);
int64_t int64Out = 0;
void* pointer = NULL;
char* strOut = NULL;
args_setInt(args, "int64Test", (int64_t)22221);
args_setPtr(args, "pointerTest", (void*)2222322);
args_setStr(args, "strTest", "teeeds");
int64Out = args_getInt(args, "int64Test");
pointer = args_getPtr(args, "pointerTest");
strOut = args_getStr(args, "strTest");
EXPECT_EQ(int64Out, 22221);
EXPECT_EQ((uint64_t)pointer, 2222322);
EXPECT_EQ(1, strEqu("teeeds", strOut));
EXPECT_EQ(args_getType(args, "int64Test"), ARG_TYPE_INT);
EXPECT_EQ(args_getType(args, "pointerTest"), ARG_TYPE_POINTER);
EXPECT_EQ(args_getType(args, "strTest"), ARG_TYPE_STRING);
args_deinit(args);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, test3) {
Args* args1 = New_args(NULL);
Args* args2 = New_args(NULL);
args_setFloat(args1, "argtest1", 2.883);
args_setStr(args1, "strtest1", "teststr");
args_copyArgByName(args1, "argtest1", args2);
args_copyArgByName(args1, "strtest1", args2);
EXPECT_FLOAT_EQ(2.8830, args_getFloat(args1, "argtest1"));
args_deinit(args1);
args_deinit(args2);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, buff) {
Args* buffs = New_args(NULL);
args_getBuff(buffs, 256);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, update) {
Args* args = New_args(NULL);
args_setInt(args, "testInt", 124);
args_setInt(args, "testInt", 125);
EXPECT_EQ(125, args_getInt(args, "testInt"));
args_deinit(args);
EXPECT_EQ(pikaMemNow(), 0);
}
// TEST(args, print_int) {
// Args* args = New_args(NULL);
// args_setInt(args, "testInt", 124);
// EXPECT_STREQ("124", args_print(args, "testInt"));
// args_deinit(args);
// EXPECT_EQ(pikaMemNow(), 0);
// }
// TEST(args, test5) {
// int32_t testInt = 124;
// Args* args = New_args(NULL);
// args_bind(args, "i", "testInt", &testInt);
// char* type = args_getType(args, "testInt");
// args_print(args, "testInt");
// EXPECT_STREQ("124", args_print(args, "testInt"));
// args_deinit(args);
// EXPECT_EQ(pikaMemNow(), 0);
// }
// TEST(args, test6) {
// Args* args = New_args(NULL);
// args_setFloat(args, "testfloat", 1.42);
// EXPECT_STREQ("1.420000", args_print(args, "testfloat"));
// args_deinit(args);
// EXPECT_EQ(pikaMemNow(), 0);
// }
// TEST(args, test7) {
// Args* args = New_args(NULL);
// float floatBindTest = 2.314;
// args_bind(args, "f", "floatBind", &floatBindTest);
// EXPECT_STREQ("2.314000", args_print(args, "floatBind"));
// args_deinit(args);
// EXPECT_EQ(pikaMemNow(), 0);
// }
// TEST(args, test8) {
// Args* args = New_args(NULL);
// args_setStr(args, "testString", "test string print");
// EXPECT_STREQ("test string print", args_print(args, "testString"));
// args_deinit(args);
// EXPECT_EQ(pikaMemNow(), 0);
// }
// TEST(args, test9) {
// Args* args = New_args(NULL);
// char strBindTest[] = "test string bind";
// args_bindStr(args, "testStringBind", (char**)&strBindTest);
// EXPECT_STREQ("test string bind",
// args_print(args, "testStringBind"));
// args_deinit(args);
// EXPECT_EQ(pikaMemNow(), 0);
// }
TEST(args, test12) {
Args* args = New_args(NULL);
args_setInt(args, "test", 13);
args_setInt(args, "kw", 25);
EXPECT_EQ(2, args_getSize(args));
EXPECT_EQ(13, (int)args_getInt(args, "test"));
args_removeArg(args, args_getArg(args, "test"));
EXPECT_EQ(1, args_getSize(args));
EXPECT_EQ(_PIKA_INT_ERR, (int)args_getInt(args, "test"));
args_deinit(args);
EXPECT_EQ(pikaMemNow(), 0);
}
struct test {
int a;
float b;
int c;
};
TEST(args, struct_) {
Args* args = New_args(NULL);
struct test test_struct = {1, 2.2, 4};
args_setStruct(args, "test", test_struct);
struct test* out_struct = (struct test*)args_getStruct(args, "test");
EXPECT_EQ(out_struct->a, 1);
EXPECT_FLOAT_EQ(out_struct->b, 2.2);
EXPECT_EQ(out_struct->c, 4);
args_deinit(args);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, mem) {
EXPECT_EQ(pikaMemNow(), mem);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, index) {
Args* args = New_args(NULL);
args_pushArg(args, arg_newInt(1));
args_pushArg(args, arg_newFloat(2.4));
int a = arg_getInt(args_getArgByIndex(args, 1));
float b = arg_getFloat(args_getArgByIndex(args, 0));
/* assert */
EXPECT_EQ(a, 1);
EXPECT_FLOAT_EQ(b, 2.4);
/* check memory */
args_deinit(args);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, int_float_convert) {
Args* args = New_args(NULL);
args_setInt(args, "a", 10);
args_setFloat(args, "b", 2.333);
float a = args_getFloat(args, "a");
int b = args_getInt(args, "b");
/* assert */
EXPECT_EQ(a, 10);
EXPECT_FLOAT_EQ(b, 2);
/* check memory */
args_deinit(args);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, heap_struct) {
ByteCodeFrame bytecode_frame;
byteCodeFrame_init(&bytecode_frame);
bytecode_frame.const_pool.size = 100;
Args* args = New_args(NULL);
args_setHeapStruct(args, "a", bytecode_frame, byteCodeFrame_deinit);
ByteCodeFrame* bf_out = (ByteCodeFrame*)args_getHeapStruct(args, "a");
/* assert */
EXPECT_EQ(bf_out->const_pool.size, 100);
/* check memory */
args_deinit(args);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, heap_struct_override) {
ByteCodeFrame bytecode_frame;
byteCodeFrame_init(&bytecode_frame);
bytecode_frame.const_pool.size = 100;
ByteCodeFrame bytecode_frame_1;
byteCodeFrame_init(&bytecode_frame_1);
bytecode_frame_1.const_pool.size = 100;
Args* args = New_args(NULL);
args_setHeapStruct(args, "a", bytecode_frame, byteCodeFrame_deinit);
args_setHeapStruct(args, "a", bytecode_frame_1, byteCodeFrame_deinit);
ByteCodeFrame* bf_out = (ByteCodeFrame*)args_getHeapStruct(args, "a");
/* assert */
EXPECT_EQ(bf_out->const_pool.size, 100);
/* check memory */
args_deinit(args);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, args_move) {
Args* args = New_args(NULL);
Args* args2 = New_args(NULL);
args_setInt(args, "a", 100);
args_moveArg(args, args2, args_getArg(args, "a"));
/* assert */
EXPECT_EQ(_PIKA_INT_ERR, args_getInt(args, "a"));
EXPECT_EQ(100, args_getInt(args2, "a"));
/* deinit */
args_deinit(args);
args_deinit(args2);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(args, args_mem) {
uint8_t mem_test[] = {0x33, 0x55, 0x00, 0x15};
Args* args = New_args(NULL);
args_setBytes(args, "mem", mem_test, sizeof(mem_test));
size_t mem_size = args_getBytesSize(args, "mem");
char* mem_test_out = (char*)args_getBytes(args, "mem");
EXPECT_EQ(mem_size, sizeof(mem_test));
EXPECT_EQ(mem_test_out[0], 0x33);
EXPECT_EQ(mem_test_out[1], 0x55);
EXPECT_EQ(mem_test_out[2], 0x00);
EXPECT_EQ(mem_test_out[3], 0x15);
args_deinit(args);
}
TEST(args, dict) {
PikaDict* dict = New_pikaDict();
int64_t int64Out = 0;
void* pointer = NULL;
char* strOut = NULL;
pikaDict_setInt(dict, "int64Test", (int64_t)22221);
pikaDict_setPtr(dict, "pointerTest", (void*)2222322);
pikaDict_setStr(dict, "strTest", "teeeds");
int64Out = pikaDict_getInt(dict, "int64Test");
pointer = pikaDict_getPtr(dict, "pointerTest");
strOut = pikaDict_getStr(dict, "strTest");
EXPECT_EQ(int64Out, 22221);
EXPECT_EQ((uint64_t)pointer, 2222322);
EXPECT_EQ(1, strEqu("teeeds", strOut));
EXPECT_EQ(pikaDict_getType(dict, "int64Test"), ARG_TYPE_INT);
EXPECT_EQ(pikaDict_getType(dict, "pointerTest"), ARG_TYPE_POINTER);
EXPECT_EQ(pikaDict_getType(dict, "strTest"), ARG_TYPE_STRING);
pikaDict_deinit(dict);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_END

View File

@ -1,236 +0,0 @@
#include "test_common.h"
TEST_START
#if PIKA_SYNTAX_SLICE_ENABLE
TEST(builtin, bytes) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/bytes.py");
/* collect */
uint8_t* res = obj_getBytes(pikaMain, "res");
/* assert */
EXPECT_EQ(res[1], 1);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
#if PIKA_BUILTIN_STRUCT_ENABLE
TEST(builtin, type1) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/type.py");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
EXPECT_STREQ(log_buff[0], "OK\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
TEST(builtin, seek) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/seek.py");
/* collect */
int len = obj_getInt(pikaMain, "len");
/* assert */
EXPECT_EQ(len, 3576);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL)
TEST(builtin, file2) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/file2.py");
/* collect */
char* s = obj_getStr(pikaMain, "s");
/* assert */
EXPECT_STREQ(s, "import PikaStdLib\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
TEST(builtin, file3) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/file3.py");
/* collect */
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
#if (PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL) && !PIKA_POOL_ENABLE
TEST(builtin, bigfile) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/bigfile.py");
/* collect */
// uint8_t* b = obj_getBytes(pikaMain, "b");
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
TEST(builtin, nofound) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/file_nofound.py");
/* collect */
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
TEST(builtin, callback_1) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "test/python/callback/test1.py");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[0], "b\r\n");
EXPECT_STREQ(log_buff[1], "a\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
#if !PIKA_NANO_ENABLE
TEST(builtin, utf8) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "../../examples/BuiltIn/utf8.py");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[2], "你好,Hello, Bonjour.\r\n");
EXPECT_STREQ(log_buff[1], "你好Hello, Bonjour.\r\n");
EXPECT_STREQ(log_buff[0], "Hi, Hello, Bonjour.\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(builtin, str_join) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "test/python/builtin/str_join.py");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
EXPECT_STREQ(log_buff[0], "PASS\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(builtin, int_extern) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "test/python/builtin/int_extern.py");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
EXPECT_STREQ(log_buff[0], "PASS\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_RUN_SINGLE_FILE_PASS(builtin,
list_tuple_equ,
"test/python/builtin/list_tuple_equ.py")
TEST_RUN_SINGLE_FILE_PASS(builtin,
fn_default1,
"test/python/builtin/fn_default1.py")
TEST_RUN_SINGLE_FILE_PASS(builtin,
fn_default_tuple,
"test/python/builtin/fn_default_tuple.py")
TEST_RUN_SINGLE_FILE_PASS(builtin, max_min, "test/python/builtin/max_min.py")
TEST_RUN_SINGLE_FILE_PASS(builtin, split, "test/python/builtin/split.py")
TEST_RUN_LINES_EXCEPT_OUTPUT(builtin,
split_slice,
"'test'.split('e')[0]",
"'t'\r\n")
TEST_RUN_LINES_EXCEPT_OUTPUT(builtin,
split_slice_1,
"'test'.split('e')[1]",
"'st'\r\n")
TEST_RUN_LINES_EXCEPT_OUTPUT(builtin,
replace_split_0,
"'a b c d'.replace(' ', ',').split(',')[0]",
"'a'\r\n")
TEST_RUN_SINGLE_FILE_EXCEPT_OUTPUT(builtin,
class_script,
"test/python/builtin/class_script.py",
"Obj1.test\r\n")
TEST_RUN_SINGLE_FILE_EXCEPT_OUTPUT(builtin,
class_hint,
"test/python/builtin/class_hint.py",
"1\r\n")
TEST_RUN_SINGLE_FILE(builtin, isinstance, "test/python/builtin/isinstance.py")
#endif
TEST_END

View File

@ -1,118 +0,0 @@
#include "test_common.h"
TEST_START
#if !PIKA_NANO_ENABLE
TEST(class, class_par) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
/* run */
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
obj_run(self, "pi = PikaMath.Math.pi\n");
/* assert */
pika_float pi = obj_getFloat(self, "pi");
#if PIKA_FLOAT_TYPE_DOUBLE
EXPECT_DOUBLE_EQ(pi, 3.141592653589793115997963468544185161590576171875l);
#else
EXPECT_FLOAT_EQ(pi, 3.141592653589793115997963468544185161590576171875l);
#endif
/* deinit */
obj_deinit(self);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(class, classpar1) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
/* run */
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(self, "../../examples/Class/classpar1.py");
/* assert */
EXPECT_STREQ(log_buff[4], "BEGIN\r\n");
EXPECT_STREQ(log_buff[3], "1\r\n");
EXPECT_STREQ(log_buff[2], "test\r\n");
EXPECT_STREQ(log_buff[1], "2\r\n");
EXPECT_STREQ(log_buff[0], "pewq\r\n");
/* deinit */
obj_deinit(self);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(class, static_method) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
/* run */
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
obj_run(self,
"import PikaMath\n"
"a = PikaMath.Operator.plusInt(10, 20)\n");
/* collect */
int a = obj_getInt(self, "a");
/* assert */
EXPECT_EQ(a, 30);
/* deinit */
obj_deinit(self);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
TEST(class, dir_) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
/* run */
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
obj_run(self,
"class T:\n"
" def a(self):\n"
" return 1\n"
"t = T()\n"
"l = dir(t)\n"
"print(l)\n");
/* collect */
/* assert */
/* deinit */
obj_deinit(self);
EXPECT_EQ(pikaMemNow(), 0);
}
extern "C" {
void builtins_intMethod(PikaObj* self, Args* args);
method_typedef(builtins_int, "int", "arg");
void builtins_floatMethod(PikaObj* self, Args* args);
method_typedef(builtins_float, "float", "arg");
void builtins_printMethod(PikaObj* self, Args* args);
method_typedef(builtins_print, "print", "*val,**ops");
class_def(PikaStdLib_SysObj){
method_def(builtins_int, hash_time33("int")),
method_def(builtins_float, hash_time33("float")),
method_def(builtins_print, hash_time33("print")),
};
class_inhert(PikaStdLib_SysObj, TinyObj);
PikaObj* New_NativeMethodBase(Args* args) {
PikaObj* self = New_TinyObj(NULL);
obj_setClass(self, PikaStdLib_SysObj);
return self;
}
}
TEST(class, native_class1) {
PikaObj* native_obj = newRootObj("root", New_NativeMethodBase);
obj_run(native_obj,
"print('hello', 123)\n"
"int(123.0000)\n"
"float(123)\n");
obj_deinit(native_obj);
EXPECT_STREQ(log_buff[1], "123\r\n");
EXPECT_STREQ(log_buff[0], "123.000000\r\n");
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_END

View File

@ -1,23 +0,0 @@
#include "test_common.h"
TEST_START
#if !PIKA_NANO_ENABLE
TEST(closure, defdef){
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
pikaVM_runSingleFile(pikaMain, "test/python/closure/defdef.py");
obj_deinit(pikaMain);
EXPECT_STREQ(log_buff[0], "in test2\r\n");
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(closure, defvardef){
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
pikaVM_runSingleFile(pikaMain, "test/python/closure/defvardef.py");
obj_deinit(pikaMain);
EXPECT_STREQ(log_buff[0], "in test2 var: 1\r\n");
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
TEST_END

View File

@ -1,18 +0,0 @@
#include "test_common.h"
TEST_START
TEST(cmodule, print_) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain, "print('test', 'test2')\n");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[0], "test test2\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_END

View File

@ -1,783 +0,0 @@
#include "test_common.h"
TEST_START
TEST(compiler, file) {
char* lines =
"len = calls.len()\n"
"mode = 'none'\n"
"info_index = 0\n"
"for i in range(0, len):\n"
" if len == 0:\n"
" break\n"
" if info_index == 0:\n"
" mode = calls[i]\n"
" info_index = 1\n"
" elif info_index == 1:\n"
" if mode == 'always':\n"
" todo = calls[i]\n"
" todo()\n"
" info_index = 0\n"
" elif mode == 'when':\n"
" when = calls[i]\n"
" info_index = 2\n"
" elif mode == 'period_ms':\n"
" period_ms = calls[i]\n"
" info_index = 2\n"
" elif info_index == 2:\n"
" if mode == 'when':\n"
" if when():\n"
" todo = calls[i]\n"
" todo()\n"
" info_index = 0\n"
" elif mode == 'period_ms':\n"
" todo = calls[i]\n"
" info_index = 3\n"
" elif info_index == 3:\n"
" if mode == 'period_ms':\n"
" if tick > calls[i]:\n"
" todo()\n"
" calls[i] = tick + period_ms\n"
" info_index = 0\n"
"\n";
pikaCompile("task.bin", lines);
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, task) {
char* lines =
"len = calls.len()\n"
"mode = 'none'\n"
"info_index = 0\n"
"for i in range(0, len):\n"
" if len == 0:\n"
" break\n"
" if info_index == 0:\n"
" mode = calls[i]\n"
" info_index = 1\n"
" elif info_index == 1:\n"
" if mode == 'always':\n"
" todo = calls[i]\n"
" todo()\n"
" info_index = 0\n"
" elif mode == 'when':\n"
" when = calls[i]\n"
" info_index = 2\n"
" elif mode == 'period_ms':\n"
" period_ms = calls[i]\n"
" info_index = 2\n"
" elif info_index == 2:\n"
" if mode == 'when':\n"
" if when():\n"
" todo = calls[i]\n"
" todo()\n"
" info_index = 0\n"
" elif mode == 'period_ms':\n"
" todo = calls[i]\n"
" info_index = 3\n"
" elif info_index == 3:\n"
" if mode == 'period_ms':\n"
" if tick > calls[i]:\n"
" todo()\n"
" calls[i] = tick + period_ms\n"
" info_index = 0\n"
"\n";
Args buffs = {0};
char* pikaAsm = pika_lines2Asm(&buffs, lines);
ByteCodeFrame bytecode_frame;
byteCodeFrame_init(&bytecode_frame);
byteCodeFrame_appendFromAsm(&bytecode_frame, pikaAsm);
/* do something */
byteCodeFrame_print(&bytecode_frame);
printf("Asm size: %d\r\n", (int)strGetSize(pikaAsm));
byteCodeFrame_printAsArray(&bytecode_frame);
/* deinit */
byteCodeFrame_deinit(&bytecode_frame);
strsDeinit(&buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, demo1) {
char* lines = "append(__val)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, snake_file) {
char* lines =
"from PikaObj import *\n"
"import PikaStdLib\n"
"import machine \n"
"\n"
"# hardware init\n"
"lcd = machine.LCD()\n"
"lcd.init()\n"
"lcd.clear('white')\n"
"key = machine.KEY()\n"
"key.init()\n"
"time = machine.Time()\n"
"x_max = 120\n"
"y_max = 150\n"
"\n"
"# snake init\n"
"s = machine.Point()\n"
"w = 9\n"
"h = 9\n"
"s.x = 50\n"
"s.y = 10\n"
"len = 0\n"
"while len < 3:\n"
" b = s\n"
" i = 0\n"
" while i < len:\n"
" b = b.next\n"
" i = i + 1\n"
" b.next = machine.Point()\n"
" b.next.x = b.x - 10\n"
" b.next.y = b.y\n"
" b.next.prev = b\n"
" len = len + 1\n"
"# ring link\n"
"b.next = s\n"
"s.prev = b\n"
"\n"
"i = 0\n"
"b = s\n"
"while i < len:\n"
" lcd.fill(b.x, b.y, w, h, 'blue')\n"
" b = b.next\n"
" i = i + 1\n"
"\n"
"print('snake lengh')\n"
"print(len)\n"
"\n"
"# fruit init\n"
"f = machine.Point()\n"
"f.x = 30\n"
"f.y = 20\n"
"lcd.fill(f.x, f.y, w, h, 'green')\n"
"\n"
"# memory check\n"
"mem = PikaStdLib.MemChecker()\n"
"print('mem used max:')\n"
"mem.max()\n"
"\n"
"# main loop\n"
"d = 0\n"
"isUpdate = 1\n"
"isEat = 0\n"
"while True:\n"
" if isUpdate:\n"
" # isUpdate = 0\n"
" # check eat fruit\n"
" if f.x == s.x and f.y == s.y:\n"
" # have eat fruit\n"
" isEat = 1\n"
" f.x = f.x + 30\n"
" if f.x > x_max:\n"
" f.x = f.x - x_max\n"
" f.y = f.y + 30\n"
" if f.y > y_max:\n"
" f.y = f.y - y_max\n"
" lcd.fill(f.x, f.y, w, h, 'green')\n"
" # move snake by the direction\n"
" if d == 0:\n"
" x_new = s.x + 10\n"
" y_new = s.y\n"
" if x_new > x_max:\n"
" x_new = 0\n"
" elif d == 1:\n"
" x_new = s.x\n"
" y_new = s.y - 10\n"
" if y_new < 0:\n"
" y_new = y_max\n"
" elif d == 2:\n"
" x_new = s.x\n"
" y_new = s.y + 10\n"
" if y_new > y_max:\n"
" y_new = 0\n"
" elif d == 3:\n"
" x_new = s.x - 10\n"
" y_new = s.y\n"
" if x_new < 0:\n"
" x_new = x_max\n"
" if isEat:\n"
" isEat = 0\n"
" b_new = machine.Point()\n"
" b_new.x = x_new\n"
" b_new.y = y_new\n"
" b_new.prev = s.prev\n"
" b_new.next = s\n"
" s.prev.next = b_new\n"
" s.prev = b_new\n"
" s = b_new\n"
" len = len + 1\n"
" print('snake lengh')\n"
" print(len)\n"
" print('mem used max:')\n"
" mem.max()\n"
" # drow the snake and fruit\n"
" # clear last body\n"
" lcd.fill(s.prev.x, s.prev.y, w, h, 'white')\n"
" # new body\n"
" s.prev.x = x_new\n"
" s.prev.y = y_new\n"
" # head is last body\n"
" s = s.prev\n"
" lcd.fill(s.x, s.y, w, h, 'blue')\n"
" b = s\n"
" i = 0\n"
" # scan key\n"
" key_val = key.get()\n"
" if key_val == 0:\n"
" d = 0\n"
" isUpdate = 1\n"
" elif key_val == 1:\n"
" d = 1\n"
" isUpdate = 1\n"
" elif key_val == 2:\n"
" d = 2\n"
" isUpdate = 1\n"
" elif key_val == 3:\n"
" d = 3\n"
" isUpdate = 1\n";
pikaCompile("snake.bin", lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, import_bf_mem) {
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
char* lines =
"def mytest():\n"
" print('test')\n"
"\n";
ByteCodeFrame bf;
byteCodeFrame_init(&bf);
pika_lines2Bytes(&bf, lines);
obj_importModuleWithByteCodeFrame(pikaMain, "mtest", &bf);
byteCodeFrame_deinit(&bf);
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, import_bf1) {
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
char* lines =
"def mytest():\n"
" print('test_import_bf1')\n"
"\n";
ByteCodeFrame bf;
byteCodeFrame_init(&bf);
pika_lines2Bytes(&bf, lines);
obj_importModuleWithByteCodeFrame(pikaMain, "mtest", &bf);
obj_run(pikaMain,
"mtest.mytest()\n"
"\n");
EXPECT_STREQ(log_buff[0], "test_import_bf1\r\n");
byteCodeFrame_deinit(&bf);
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, import_bf2) {
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
char* lines =
"class Test:\n"
" def mytest(self):\n"
" print('test_import_bf2')\n"
"\n";
ByteCodeFrame bf;
byteCodeFrame_init(&bf);
pika_lines2Bytes(&bf, lines);
obj_importModuleWithByteCodeFrame(pikaMain, "mtest", &bf);
obj_run(pikaMain,
"m = mtest.Test()\n"
"m.mytest()\n"
"\n");
byteCodeFrame_deinit(&bf);
obj_deinit(pikaMain);
EXPECT_STREQ(log_buff[0], "test_import_bf2\r\n");
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, file1) {
pikaCompileFile("test/python/main.py");
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, file2) {
pikaCompileFile("test/python/main_snake_LCD.py");
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, init) {
LibObj* lib = New_LibObj(NULL);
LibObj_deinit(lib);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, lib_link_bytecode) {
LibObj* lib = New_LibObj(NULL);
LibObj_dynamicLink(lib, "module1", (uint8_t*)0x3344);
LibObj_dynamicLink(lib, "module2", (uint8_t*)0x33433);
LibObj_dynamicLink(lib, "module3", (uint8_t*)0x33433);
LibObj_dynamicLink(lib, "module4", (uint8_t*)0x33433);
LibObj_dynamicLink(lib, "module5", (uint8_t*)0x33433);
EXPECT_STREQ(obj_getStr(lib, "module1.name"), "module1");
EXPECT_EQ((uintptr_t)obj_getPtr(lib, "module1.bytecode"), 0x3344);
/* deinit */
LibObj_deinit(lib);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, lib_push_file) {
LibObj* lib = New_LibObj(NULL);
LibObj_staticLinkFile(lib, "test/python/main.py.o");
/* deinit */
LibObj_deinit(lib);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, lib_push_files) {
LibObj* lib = New_LibObj(NULL);
LibObj_staticLinkFile(lib, "test/python/main.py.o");
LibObj_staticLinkFile(lib, "test/python/main_snake_LCD.py.o");
LibObj_listModules(lib);
/* asset */
EXPECT_STREQ(log_buff[0], "main\r\n");
EXPECT_STREQ(log_buff[1], "main_snake_LCD\r\n");
/* deinit */
LibObj_deinit(lib);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, lib_compile_link) {
LibObj* lib = New_LibObj(NULL);
pikaCompileFile("test/python/UnitTest.py");
pikaCompileFile("test/python/main.py");
pikaCompileFile("test/python/main_snake_LCD.py");
LibObj_staticLinkFile(lib, "test/python/UnitTest.py.o");
LibObj_staticLinkFile(lib, "test/python/main.py.o");
LibObj_staticLinkFile(lib, "test/python/main_snake_LCD.py.o");
LibObj_listModules(lib);
/* asset */
EXPECT_STREQ(log_buff[0], "UnitTest\r\n");
EXPECT_STREQ(log_buff[1], "main\r\n");
EXPECT_STREQ(log_buff[2], "main_snake_LCD\r\n");
/* deinit */
LibObj_deinit(lib);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, compile_link_import) {
LibObj* lib = New_LibObj(NULL);
pikaCompileFile("test/python/test_module1.py");
LibObj_staticLinkFile(lib, "test/python/test_module1.py.o");
LibObj_listModules(lib);
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
obj_linkLibObj(pikaMain, lib);
obj_run(pikaMain,
"import test_module1\n"
"test_module1.mytest()\n");
/* asset */
EXPECT_STREQ(log_buff[0], "test_module_1_hello\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, lib_to_file) {
LibObj* lib = New_LibObj(NULL);
pikaCompileFile("test/python/UnitTest.py");
pikaCompileFile("test/python/main.py");
pikaCompileFile("test/python/main_snake_LCD.py");
LibObj_staticLinkFile(lib, "test/python/UnitTest.py.o");
LibObj_staticLinkFile(lib, "test/python/main.py.o");
LibObj_staticLinkFile(lib, "test/python/main_snake_LCD.py.o");
LibObj_listModules(lib);
LibObj_saveLibraryFile(lib, "test/python/lib_to_file.py.a");
/* asset */
EXPECT_STREQ(log_buff[0], "UnitTest\r\n");
EXPECT_STREQ(log_buff[1], "main\r\n");
EXPECT_STREQ(log_buff[2], "main_snake_LCD\r\n");
/* deinit */
LibObj_deinit(lib);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, save2) {
LibObj* lib = New_LibObj(NULL);
pikaCompileFile("test/python/test_module1.py");
pikaCompileFile("test/python/test_module2.py");
pikaCompileFile("test/python/test_module3.py");
LibObj_staticLinkFile(lib, "test/python/test_module1.py.o");
LibObj_staticLinkFile(lib, "test/python/test_module2.py.o");
LibObj_staticLinkFile(lib, "test/python/test_module3.py.o");
LibObj_listModules(lib);
LibObj_saveLibraryFile(lib, "test/python/test_module.py.a");
/* asset */
EXPECT_STREQ(log_buff[0], "test_module1\r\n");
EXPECT_STREQ(log_buff[1], "test_module2\r\n");
EXPECT_STREQ(log_buff[2], "test_module3\r\n");
/* deinit */
LibObj_deinit(lib);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, load_file) {
/* compile */
LibObj* lib = New_LibObj(NULL);
LibObj_loadLibraryFile(lib, "test/python/test_module.py.a");
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
obj_linkLibObj(pikaMain, lib);
obj_run(pikaMain,
"import test_module1\n"
"import test_module2\n"
"import test_module3\n"
"test_module1.mytest()\n"
"test_module2.mytest()\n"
"test_module3.mytest()\n");
/* asset */
EXPECT_STREQ(log_buff[2], "test_module_1_hello\r\n");
EXPECT_STREQ(log_buff[1], "test_module_2_hello\r\n");
EXPECT_STREQ(log_buff[0], "test_module_3_hello\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, load_no_file) {
/* compile */
LibObj* lib = New_LibObj(NULL);
int res = LibObj_loadLibraryFile(lib, "test/python/mian.py.o");
EXPECT_EQ(res, PIKA_RES_ERR_IO_ERROR);
/* deinit */
LibObj_deinit(lib);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, load_err_file_type) {
/* compile */
LibObj* lib = New_LibObj(NULL);
int res = LibObj_loadLibraryFile(lib, "test/python/main.py.o");
EXPECT_EQ(res, PIKA_RES_ERR_OPERATION_FAILED);
/* deinit */
LibObj_deinit(lib);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, lib_file_to_array) {
Lib_loadLibraryFileToArray("test/python/lib_to_file.py.a", "test/python");
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(make, maker) {
PikaMaker* maker = New_PikaMaker();
pikaMaker_deinit(maker);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(make, compile) {
PikaMaker* maker = New_PikaMaker();
pikaMaker_setPWD(maker, "package/pikascript/");
pikaMaker_compileModule(maker, "main");
pikaMaker_deinit(maker);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(make, depend) {
PikaMaker* maker = New_PikaMaker();
pikaMaker_setPWD(maker, "package/pikascript/");
pikaMaker_getDependencies(maker, "main");
pikaMaker_printStates(maker);
// char* uncompiled = pikaMaker_getFirstNocompiled(maker);
// EXPECT_STREQ(uncompiled, "test_module1");
pikaMaker_deinit(maker);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(make, compile_depend) {
PikaMaker* maker = New_PikaMaker();
pikaMaker_setPWD(maker, "package/pikascript/");
pikaMaker_getDependencies(maker, "main");
char* uncompiled = pikaMaker_getFirstNocompiled(maker);
pika_assert(NULL != uncompiled);
pikaMaker_compileModule(maker, uncompiled);
pikaMaker_getDependencies(maker, uncompiled);
uncompiled = pikaMaker_getFirstNocompiled(maker);
// EXPECT_STREQ(uncompiled, "test_module3");
pikaMaker_printStates(maker);
pikaMaker_deinit(maker);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(make, compile_depend_all) {
PikaMaker* maker = New_PikaMaker();
pikaMaker_setPWD(maker, "package/pikascript/");
pikaMaker_compileModuleWithDepends(maker, "main");
pikaMaker_printStates(maker);
pikaMaker_deinit(maker);
EXPECT_EQ(pikaMemNow(), 0);
}
// TEST(make, compile_link_all) {
// PikaMaker* maker = New_PikaMaker();
// pikaMaker_setPWD(maker, "package/pikascript/");
// pikaMaker_compileModuleWithDepends(maker, "main");
// pikaMaker_printStates(maker);
// pikaMaker_linkCompiledModules(maker, "pikaModules.py.a");
// pikaMaker_deinit(maker);
// EXPECT_EQ(pikaMemNow(), 0);
// }
TEST(compiler, __str__) {
char* lines = "@res_str = __str__()";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __len__) {
char* lines = "@res_len = __len__()";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __del__) {
char* lines = "__del__()";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, event_cb) {
char* lines = "_eventCallBack(_eventSignal)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, event_cb_lvgl) {
char* lines = "_res = eventCallBack(eventData)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __setitem__) {
char* lines = "__setitem__(__key, __val)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __getitem__) {
char* lines = "@res_item = __getitem__(__key)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __add__) {
char* lines = "@res_add = __add__(__others)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __iter__) {
char* lines = "@res_iter = __iter__()";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __sub__) {
char* lines = "@res_sub = __sub__(__others)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __contains__) {
char* lines = "@res_contains = __contains__(__others)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __callback) {
char* lines = "__callback(__frameBuffer, __isNewFrame)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, __list) {
char* lines =
"@res_list = []\n"
"for __item in __list:\n"
" @res_list.append(__item)\n"
"del __item\n"
"del __list\n";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, getattr) {
char* lines = "@res = __getattribute__(@name)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, getattr2) {
char* lines = "@res = __getattr__(@name)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, setattr) {
char* lines = "__setattr__(@name, @value)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, dict_update) {
char* lines =
"for @item in @other:\n"
" @self[@item] = @other[@item]\n";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, i_pp) {
char* lines =
"i = 0\n"
"while i < 10000:\n"
" i += 1\n";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, benchmark) {
char* lines =
"num = 0\n"
"i = 2\n"
"while i < 1000:\n"
" is_prime = 1\n"
" j = 2\n"
" while j < i:\n"
" if i%j==0 :\n"
" is_prime = 0\n"
" break\n"
" j += 1 \n"
" if is_prime:\n"
" num = num + i\n"
" i += 1\n"
"\n";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, for_print_1k) {
char* lines =
"for i in range(1000):\n"
" print(i)\n";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, bc_fn) {
char* lines =
"def test():\n"
" print('test')\n";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, starrd) {
char* lines = "@l = __len__()";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, starrd_get) {
char* lines = "@a = __getitem__(@d)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, thread_arg) {
char* lines = "thread(*args)";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, prime_100) {
char* lines =
"num = 0\n"
"i = 2\n"
"for i in range(2,100):\n"
" j=2\n"
" is_prime = 1\n"
" for j in range(2,i):\n"
" if i%j==0 :\n"
" is_prime = 0\n"
" break\n"
" if is_prime:\n"
" num = num + i\n"
"\n";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, getattr_fn) {
char* lines = "@res = @obj.@name\n";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, str_join) {
char* lines =
"@res_join = \"\"\n"
"@num = len(@val)\n"
"for i in range(@num):\n"
" @res_join += @val[i]\n"
" if i != @num - 1:\n"
" @res_join += @str\n";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, thread_void_arg) {
char* lines = "thread()";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, max) {
char* lines =
"@res_max = @list[0]\n"
"for @item in @list:\n"
" if @item > @res_max:\n"
" @res_max = @item\n";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(compiler, min) {
char* lines =
"@res_max = @list[0]\n"
"for @item in @list:\n"
" if @item < @res_max:\n"
" @res_max = @item\n";
pika_lines2Array(lines);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_END

View File

@ -1,65 +0,0 @@
#include "test_common.h"
TEST_START
#if !PIKA_NANO_ENABLE
#define TEST_FILE2DOC(_test_name_, _file_name_) \
TEST(doc, _test_name_) { \
/* init */ \
g_PikaMemInfo.heapUsedMax = 0; \
/* run */ \
Parser* parser = New_parser(); \
char* docString = parser_file2Doc(parser, (_file_name_)); \
printf("%s", docString); \
/* collect */ \
/* assert */ \
/* deinit */ \
parser_deinit(parser); \
EXPECT_EQ(pikaMemNow(), 0); \
}
#define TEST_FILE2DOCFILE(_test_name_, _file_name_, _doc_name_) \
TEST(doc, _test_name_) { \
/* init */ \
g_PikaMemInfo.heapUsedMax = 0; \
/* run */ \
Parser* parser = New_parser(); \
parser_file2DocFile(parser, (_file_name_), (_doc_name_)); \
/* collect */ \
/* assert */ \
/* deinit */ \
parser_deinit(parser); \
EXPECT_EQ(pikaMemNow(), 0); \
}
TEST_FILE2DOC(_modbus, "package/pikascript/_modbus.pyi")
TEST_FILE2DOC(modbus, "package/pikascript/modbus.py")
TEST_FILE2DOC(mqtt, "package/pikascript/mqtt.py")
TEST_FILE2DOC(_thread, "package/pikascript/_thread.pyi")
TEST_FILE2DOC(PikaStdLib, "package/pikascript/PikaStdLib.pyi")
TEST_FILE2DOC(PikaStdDevice, "package/pikascript/PikaStdDevice.pyi")
TEST_FILE2DOCFILE(PikaStdDevice_file,
"package/pikascript/PikaStdDevice.pyi",
"test/out/PikaStdDevice.md")
TEST_FILE2DOCFILE(modbus_file,
"package/pikascript/modbus.py",
"test/out/modbus.md")
TEST_FILE2DOCFILE(configparser,
"package/pikascript/configparser.py",
"test/out/configparser.md")
TEST_FILE2DOCFILE(mqtt_file, "package/pikascript/mqtt.py", "test/out/mqtt.md")
TEST_FILE2DOCFILE(requests_file, "package/pikascript/requests.py", "test/out/requests.md")
TEST_FILE2DOCFILE(PikaCV_file, "package/pikascript/PikaCV.pyi", "test/out/PikaCV.md")
#endif
TEST_END

View File

@ -1,78 +0,0 @@
#include "test_common.h"
TEST_START
extern PikaEventListener* g_pika_device_event_listener;
#if PIKA_EVENT_ENABLE
TEST(event, gpio) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
pikaVM_runSingleFile(pikaMain, "test/python/TemplateDevice/gpio_cb.py");
#define EVENT_SIGAL_IO_RISING_EDGE 0x01
#define EVENT_SIGAL_IO_FALLING_EDGE 0x02
#define GPIO_PA8_EVENT_ID 0x08
/* simulate run in the call back */
pks_eventListener_sendSignal(g_pika_device_event_listener,
GPIO_PA8_EVENT_ID, EVENT_SIGAL_IO_RISING_EDGE);
pks_eventListener_sendSignal(g_pika_device_event_listener,
GPIO_PA8_EVENT_ID,
EVENT_SIGAL_IO_FALLING_EDGE);
/* assert */
obj_run(pikaMain, "io1.eventTest()");
EXPECT_STREQ(log_buff[3], "get rising edge!\r\n");
EXPECT_STREQ(log_buff[2], "get falling edge!\r\n");
EXPECT_STREQ(log_buff[1], "get rising edge!\r\n");
EXPECT_STREQ(log_buff[0], "get falling edge!\r\n");
for (int i = 0; i < 255; i++) {
obj_run(pikaMain, "io1.eventTest()");
}
/* simulate run in the call back */
Arg* res_123 = pks_eventListener_sendSignalAwaitResult(
g_pika_device_event_listener, GPIO_PA8_EVENT_ID, 123);
Arg* res_456 = pks_eventListener_sendSignalAwaitResult(
g_pika_device_event_listener, GPIO_PA8_EVENT_ID, 456);
EXPECT_EQ(arg_getInt(res_123), 123);
EXPECT_EQ(arg_getInt(res_456), 456);
/* simulate task queue overflow */
for (int i = 0; i < PIKA_EVENT_LIST_SIZE * 2; i++) {
_do_pks_eventListener_send(
g_pika_device_event_listener, GPIO_PA8_EVENT_ID,
arg_newInt(EVENT_SIGAL_IO_FALLING_EDGE), PIKA_FALSE);
}
obj_run(pikaMain, "io1.close()");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(event, remove_regist) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
pks_eventListener_init(&g_pika_device_event_listener);
PikaObj* testobj = newNormalObj(New_TinyObj);
pks_eventListener_registEvent(g_pika_device_event_listener, 0, testobj);
EXPECT_EQ(testobj->refcnt, 2);
pks_eventListener_removeEvent(g_pika_device_event_listener, 0);
EXPECT_EQ(testobj->refcnt, 1);
/* deinit */
obj_deinit(pikaMain);
obj_GC(testobj);
pks_eventListener_deinit(&g_pika_device_event_listener);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
TEST_END

View File

@ -1,216 +0,0 @@
#include "test_common.h"
TEST_START
#if PIKA_SYNTAX_EXCEPTION_ENABLE
TEST(except, try1) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
obj_run(pikaMain,
"try:\n"
" print('before raise')\n"
" raise \n"
" print('after raise')\n"
"except:\n"
" print('in except')\n"
"\n");
/* collect */
EXPECT_STREQ("BEGIN\r\n", log_buff[2]);
EXPECT_STREQ("before raise\r\n", log_buff[1]);
EXPECT_STREQ("in except\r\n", log_buff[0]);
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(except, def_none) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
obj_run(pikaMain,
"import pika_cjson\n"
"b = pika_cjson.Parse('')\n"
"if None == b:\n"
" print('None')\n"
"\n");
/* collect */
EXPECT_STREQ("None\r\n", log_buff[0]);
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(except, trydef1) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
pikaVM_runSingleFile(pikaMain, "../../examples/Exception/trydef1.py");
/* collect */
/* assert */
EXPECT_STREQ("BEGIN\r\n", log_buff[2]);
EXPECT_STREQ("a:1\r\n", log_buff[1]);
EXPECT_STREQ("in except\r\n", log_buff[0]);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(except, try1file) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
pikaVM_runSingleFile(pikaMain, "../../examples/Exception/try1.py");
/* collect */
EXPECT_STREQ("BEGIN\r\n", log_buff[2]);
EXPECT_STREQ("before raise\r\n", log_buff[1]);
EXPECT_STREQ("in except\r\n", log_buff[0]);
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(except, for_loop) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
obj_run(pikaMain,
"sum = 0\n"
"for i in range(0, 10):\n"
" try:\n"
" if i == 3:\n"
" raise\n"
" print(i)\n"
" sum += i\n"
" except:\n"
" print('in except')\n"
"\n");
/* collect */
int sum = obj_getInt(pikaMain, "sum");
/* assert */
EXPECT_EQ(sum, 42);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(except, dict) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
pikaVM_runSingleFile(pikaMain, "../../examples/Exception/trydict.py");
/* collect */
int res = obj_getInt(pikaMain, "res");
EXPECT_EQ(res, 5);
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(except, len) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
pikaVM_runSingleFile(pikaMain, "../../examples/Exception/trylen.py");
/* collect */
int res = obj_getInt(pikaMain, "res");
EXPECT_EQ(res, 5);
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(except, trycmodule1) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
obj_run(pikaMain,
"import GTestTask\n"
"try:\n"
" GTestTask.test_raise()\n"
" print('after failed')\n"
"except:\n"
" print('parse failed')\n"
"\n");
/* collect */
EXPECT_STREQ("BEGIN\r\n", log_buff[1]);
EXPECT_STREQ("parse failed\r\n", log_buff[0]);
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(except, except_break) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
obj_run(pikaMain,
"l = [1,2,3]\n"
"sum = 0\n"
"for i in range(10):\n"
" try:\n"
" sum += l[i]\n"
" except Exception:\n"
" print('in excepton')\n"
" break\n"
"print(sum)\n"
"\n");
/* collect */
/* assert */
EXPECT_EQ(obj_getInt(pikaMain, "sum"), 6);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(except, while_try_while) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
__platform_printf("BEGIN\r\n");
/* run */
pikaVM_runSingleFile(pikaMain, "test/python/except/while_try_while.py");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[2], "before try\r\n");
EXPECT_STREQ(log_buff[1], "after try\r\n");
EXPECT_STREQ(log_buff[0], "after while\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_RUN_SINGLE_FILE(except,
try_while_return,
"test/python/except/try_while_return.py");
TEST_RUN_SINGLE_FILE(except,
isinstance,
"test/python/except/except_isinstance.py");
#endif
TEST_END

View File

@ -1,181 +0,0 @@
#include "test_common.h"
TEST_START
TEST(gc, root) {
PikaObj* root = newRootObj("root", New_PikaMain);
EXPECT_EQ(obj_refcntNow(root), 1);
Arg* refArg = arg_setRef(NULL, "", root);
EXPECT_EQ(obj_refcntNow(root), 2);
arg_deinit(refArg);
EXPECT_EQ(obj_refcntNow(root), 1);
obj_deinit(root);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(gc, ref1) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain, "mem = PikaStdLib.MemChecker()");
PikaObj* mem = (PikaObj*)obj_getPtr(pikaMain, "mem");
EXPECT_EQ(obj_refcntNow(mem), 1);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(gc, ref121) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain, "mem = PikaStdLib.MemChecker()");
PikaObj* mem = (PikaObj*)obj_getPtr(pikaMain, "mem");
EXPECT_EQ(obj_refcntNow(mem), 1);
obj_run(pikaMain, "mem2 = mem");
EXPECT_EQ(obj_refcntNow(mem), 2);
obj_removeArg(pikaMain, "mem2");
EXPECT_EQ(obj_refcntNow(mem), 1);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(gc, ref12) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain, "mem = PikaStdLib.MemChecker()");
PikaObj* mem = (PikaObj*)obj_getPtr(pikaMain, "mem");
EXPECT_EQ(obj_refcntNow(mem), 1);
obj_run(pikaMain, "mem2 = mem");
EXPECT_EQ(obj_refcntNow(mem), 2);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(gc, ref1210) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain, "mem = PikaStdLib.MemChecker()");
PikaObj* mem = (PikaObj*)obj_getPtr(pikaMain, "mem");
EXPECT_EQ(obj_refcntNow(mem), 1);
obj_run(pikaMain, "mem2 = mem");
EXPECT_EQ(obj_refcntNow(mem), 2);
obj_removeArg(pikaMain, "mem2");
EXPECT_EQ(obj_refcntNow(mem), 1);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(gc, ref_move) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain, "mem = PikaStdLib.MemChecker()");
PikaObj* mem = (PikaObj*)obj_getPtr(pikaMain, "mem");
EXPECT_EQ(obj_refcntNow(mem), 1);
obj_run(pikaMain, "mem2 = mem");
EXPECT_EQ(obj_refcntNow(mem), 2);
obj_removeArg(pikaMain, "mem");
EXPECT_EQ(obj_refcntNow(mem), 1);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(gc, factory) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain,
"def factory():\n"
" _mem = PikaStdLib.MemChecker()\n"
" return _mem\n"
"mem = factory()\n");
/* collect */
PikaObj* mem = obj_getObj(pikaMain, "mem");
EXPECT_EQ(obj_refcntNow(mem), 1);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(gc, not_out) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain, "PikaStdLib.MemChecker()\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(gc, heap_failed1) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain,
"recv_buf = PikaStdData.List()\n"
"RECV_MAX_SIZE=128\n"
"iteri = 0\n"
"for i in range(0, int(RECV_MAX_SIZE)):\n"
" recv_buf.append(0)\n"
" iteri += 1\n"
"iteri");
/* assert */
EXPECT_STREQ("128\r\n", log_buff[0]);
#if PIKA_GC_MARK_SWEEP_ENABLE
int cnt = pikaGC_count();
EXPECT_EQ(cnt != 0, 1);
pikaGC_markDump();
int cnt_marked = pikaGC_countMarked();
EXPECT_EQ(cnt, cnt_marked);
/* deinit */
#endif
obj_deinit(pikaMain);
#if PIKA_GC_MARK_SWEEP_ENABLE
cnt = pikaGC_count();
EXPECT_EQ(cnt, 0);
#endif
EXPECT_EQ(pikaMemNow(), 0);
}
#if PIKA_GC_MARK_SWEEP_ENABLE
TEST(gc, circle) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
pikaVM_runSingleFile(pikaMain, "test/python/gc/gc_circle.py");
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(gc, circle2) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
pikaVM_runSingleFile(pikaMain, "test/python/gc/gc_circle2.py");
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(gc, tree1) {
/* init */
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
pikaVM_runSingleFile(pikaMain, "test/python/gc/gc_tree1.py");
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
TEST_END

View File

@ -1,9 +0,0 @@
#include "test_common.h"
TEST_START
#if !PIKA_NANO_ENABLE
TEST_RUN_SINGLE_FILE_PASS(lua, eval, "test/python/pika_lua/eval.py")
TEST_RUN_SINGLE_FILE_PASS(lua, require, "test/python/pika_lua/require.py")
#endif
TEST_END

File diff suppressed because it is too large Load Diff

View File

@ -1,88 +0,0 @@
#include "test_common.h"
TEST_START
extern "C" {
Pool pool_init(uint32_t size, uint8_t aline);
void* pool_malloc(Pool* pool, uint32_t size);
void pool_free(Pool* pool, void* mem, uint32_t size);
void pool_deinit(Pool* pool);
void pool_printBlocks(Pool* pool, uint32_t block_min, uint32_t block_max);
}
TEST(pool, init) {
Pool p = pool_init(125, 4);
EXPECT_EQ(p.aline, 4);
EXPECT_EQ(p.size, 128);
pool_printBlocks(&p, 0, 128);
pool_deinit(&p);
EXPECT_EQ((uint64_t)p.mem, NULL);
}
TEST(pool, m1) {
Pool p = pool_init(125, 4);
EXPECT_EQ(p.aline, 4);
EXPECT_EQ(p.size, 128);
uint64_t mem1_offset = (uint64_t)pool_malloc(&p, 4) - (uint64_t)p.mem;
pool_printBlocks(&p, 0, 128);
EXPECT_EQ(1, bitmap_get(p.bitmap, 0));
EXPECT_EQ(0, bitmap_get(p.bitmap, 1));
EXPECT_EQ(0, mem1_offset);
pool_deinit(&p);
}
TEST(pool, m2) {
Pool p = pool_init(125, 4);
EXPECT_EQ(p.aline, 4);
EXPECT_EQ(p.size, 128);
uint64_t mem1_offset = (uint64_t)pool_malloc(&p, 4) - (uint64_t)p.mem;
uint64_t mem2_offset = (uint64_t)pool_malloc(&p, 4) - (uint64_t)p.mem;
pool_printBlocks(&p, 0, 128);
EXPECT_EQ(1, bitmap_get(p.bitmap, 0));
EXPECT_EQ(1, bitmap_get(p.bitmap, 1));
EXPECT_EQ(0, mem1_offset);
EXPECT_EQ(4, mem2_offset);
pool_deinit(&p);
}
TEST(pool, mf1) {
Pool p = pool_init(125, 4);
EXPECT_EQ(p.aline, 4);
EXPECT_EQ(p.size, 128);
void* mem1 = pool_malloc(&p, 4);
uint64_t mem1_offset = (uint64_t)mem1 - (uint64_t)p.mem;
EXPECT_EQ(1, bitmap_get(p.bitmap, 0));
pool_printBlocks(&p, 0, 128);
pool_free(&p, mem1, 4);
pool_printBlocks(&p, 0, 128);
EXPECT_EQ(0, bitmap_get(p.bitmap, 0));
EXPECT_EQ(0, mem1_offset);
pool_deinit(&p);
}
TEST(pool, mf2) {
Pool p = pool_init(125, 16);
EXPECT_EQ(p.aline, 16);
EXPECT_EQ(p.size, 128);
void* mem1 = pool_malloc(&p, 4);
uint64_t mem1_offset = (uint64_t)mem1 - (uint64_t)p.mem;
EXPECT_EQ(1, bitmap_get(p.bitmap, 0));
pool_printBlocks(&p, 0, 128);
pool_free(&p, mem1, 4);
pool_printBlocks(&p, 0, 128);
EXPECT_EQ(0, bitmap_get(p.bitmap, 0));
EXPECT_EQ(0, mem1_offset);
pool_deinit(&p);
}
TEST(pool, mfm1) {
Pool p = pool_init(125, 4);
EXPECT_EQ(p.size, 128);
void* mem1 = pool_malloc(&p, 4);
pool_malloc(&p, 16);
pool_free(&p, mem1, 4);
pool_malloc(&p, 16);
pool_printBlocks(&p, 0, 128);
pool_deinit(&p);
}
TEST_END

View File

@ -1,78 +0,0 @@
#include "test_common.h"
TEST_START
TEST(stack, NEW) {
Stack s;
stack_init(&s);
stack_deinit(&s);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(stack, size) {
Stack s;
stack_init(&s);
stack_pushSize(&s, 10);
stack_pushSize(&s, 20);
stack_pushSize(&s, 30);
EXPECT_EQ(stack_popSize(&s), 30);
EXPECT_EQ(stack_popSize(&s), 20);
EXPECT_EQ(stack_popSize(&s), 10);
stack_deinit(&s);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(stack, arg) {
Stack s;
stack_init(&s);
Arg* arg1 = arg_newInt(10);
Arg* arg2 = arg_newInt(20);
Arg* arg3 = arg_newInt(30);
stack_pushArg(&s, arg1);
stack_pushArg(&s, arg2);
stack_pushArg(&s, arg3);
Arg* arg4 = stack_popArg_alloc(&s);
Arg* arg5 = stack_popArg_alloc(&s);
Arg* arg6 = stack_popArg_alloc(&s);
EXPECT_EQ(arg_getInt(arg4), 30);
EXPECT_EQ(arg_getInt(arg5), 20);
EXPECT_EQ(arg_getInt(arg6), 10);
stack_deinit(&s);
arg_deinit(arg4);
arg_deinit(arg5);
arg_deinit(arg6);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(stack, str) {
Stack s;
stack_init(&s);
stack_pushStr(&s, "abc");
stack_pushStr(&s, "123");
stack_pushStr(&s, "xyz");
char buff[32] = {0};
EXPECT_STREQ(stack_popStr(&s, buff), "xyz");
EXPECT_STREQ(stack_popStr(&s, buff), "123");
EXPECT_STREQ(stack_popStr(&s, buff), "abc");
stack_deinit(&s);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(stack, get_str) {
Stack s;
stack_init(&s);
stack_pushStr(&s, "abc");
stack_pushStr(&s, "123");
stack_pushStr(&s, "xyz");
EXPECT_STREQ(arg_getStr(stack_checkArg(&s, 0)), "xyz");
EXPECT_STREQ(arg_getStr(stack_checkArg(&s, 0)), "xyz");
EXPECT_STREQ(arg_getStr(stack_checkArg(&s, 1)), "123");
EXPECT_STREQ(arg_getStr(stack_checkArg(&s, 2)), "abc");
stack_deinit(&s);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_END

View File

@ -1,155 +0,0 @@
#include "test_common.h"
TEST_START
extern PikaMemInfo g_PikaMemInfo;
/* the log_buff of printf */
extern char log_buff[LOG_BUFF_MAX][LOG_SIZE];
static void printInfo(const char* argName, char* argVal) {
printf("\t\t[info] %s: \"%s\"\r\n", argName, argVal);
}
static int mem;
TEST(strs, append) {
Args* buffs = New_strBuff();
char* res = strsAppend(buffs, "a", "b");
EXPECT_STREQ("ab", res);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(strs, formatInt) {
Args* buffs = New_strBuff();
char* res = strsFormat(buffs, 32, "test: %d", 3);
EXPECT_STREQ("test: 3", res);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(strs, analizeDef) {
mem = pikaMemNow();
Args* buffs = New_args(NULL);
char currentClassName[] = "Compiler";
char line[] = " def analizeFile(pythonApiPath: str):";
printInfo("currentClassName", currentClassName);
char* defSentenceWithBlock = strsRemovePrefix(buffs, line, " def ");
char* defSentence = strsDeleteChar(buffs, defSentenceWithBlock, ' ');
printInfo("defSentence", defSentence);
char* methodName = strsGetFirstToken(buffs, defSentence, '(');
printInfo("methodName", methodName);
char* methodObjPath =
strsAppend(buffs, strsAppend(buffs, currentClassName, "."), methodName);
printInfo("methodObjPath", methodObjPath);
char* returnType = strsCut(buffs, defSentence, '>', ':');
printInfo("returnType", returnType);
char* typeList = strsCut(buffs, defSentence, '(', ')');
printInfo("typeList", typeList);
if (0 != strGetSize(typeList)) {
int argNum = strCountSign(typeList, ',') + 1;
char* typeListBuff = strsCopy(buffs, typeList);
for (int i = 0; i < argNum; i++) {
char* typeDeclareation = strsPopToken(buffs, &typeListBuff, ',');
printInfo("typeDeclareation", typeDeclareation);
char* argName = strsGetFirstToken(buffs, typeDeclareation, ':');
printInfo("argName", argName);
char* argType = strPointToLastToken(typeDeclareation, ':');
printInfo("argType", argType);
}
}
args_deinit(buffs);
return;
}
TEST(strs, format) {
Args* buffs = New_args(NULL);
char* fmt = strsFormat(buffs, 128, "test int: %d, float %f", 1, 34.2);
EXPECT_TRUE(strEqu("test int: 1, float 34.200000", fmt));
args_deinit(buffs);
}
TEST(strs, mem) {
EXPECT_EQ(pikaMemNow(), mem);
}
TEST(strs, arg_strAppend) {
Arg* str_arg = arg_newStr("a");
str_arg = arg_strAppend(str_arg, "b");
EXPECT_STREQ(arg_getStr(str_arg), "ab");
arg_deinit(str_arg);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(strs, strsReplace) {
Args* buffs = New_strBuff();
char* res = strsReplace(buffs, "abcdefg", "cd", "47");
EXPECT_STREQ(res, "ab47efg");
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(strs, cut_) {
Args* buffs = New_strBuff();
char* res = strsCut(buffs, "print('test,test')", '(', ')');
EXPECT_STREQ(res, "'test,test'");
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(str, strPointToLastToken) {
char* tokens = "abc.efg";
char* last_token = strPointToLastToken(tokens, '.');
EXPECT_STREQ(last_token, "efg");
}
TEST(str, transfer) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_run(pikaMain, "'\\r\\n'\n");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[0], "'\r\n'\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(str, transfer_issue_jfo4i) {
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_run(pikaMain, "'\\\\replace'");
pikaVM_run(pikaMain, "'\\\\non'");
pikaVM_run(pikaMain, "'\\\\title'");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[2], "'\\replace'\r\n");
EXPECT_STREQ(log_buff[1], "'\\non'\r\n");
EXPECT_STREQ(log_buff[0], "'\\title'\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(strs, path_join) {
Args* buffs = New_strBuff();
EXPECT_STREQ(strsPathJoin(buffs, "", "test.py"), "test.py");
EXPECT_STREQ(strsPathJoin(buffs, "test", "test.py"), "test/test.py");
EXPECT_STREQ(strsPathJoin(buffs, "test/", "test.py"), "test/test.py");
EXPECT_STREQ(strsPathJoin(buffs, "test/", "/test.py"), "test/test.py");
EXPECT_STREQ(strsPathJoin(buffs, "path1", "path2/"), "path1/path2/");
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_END

View File

@ -1,134 +0,0 @@
#include "test_common.h"
TEST_START
TEST(sysObj, print) {
PikaObj* obj = newRootObj("test", New_PikaStdLib_SysObj);
VMParameters* globals = obj_run(obj, "print('hello world')");
// char* sysOut = args_getSysOut(globals->list);
int errCode = args_getErrorCode(globals->list);
// printf("sysout = %s\r\n", sysOut);
EXPECT_STREQ(log_buff[0], "hello world\r\n");
// ASSERT_STREQ("hello world", sysOut);
ASSERT_EQ(0, errCode);
// obj_deinit(globals);
obj_deinit(obj);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(sysObj, noMethod) {
PikaObj* obj = newRootObj("test", New_PikaStdLib_SysObj);
__platform_printf("BEGIN\r\n");
obj_run(obj, "printttt('hello world')");
// char* sysOut = args_getSysOut(globals->list);
// int errCode = args_getErrorCode(globals->list);
// printf("sysout = %s\r\n", sysOut);
// ASSERT_EQ(1, strEqu("[error] runner: method no found.", sysOut));
EXPECT_STREQ(log_buff[4], "NameError: name 'printttt' is not defined\r\n");
// ASSERT_EQ(2, errCode);
// obj_deinit(globals);
obj_deinit(obj);
EXPECT_EQ(pikaMemNow(), 0);
}
#if !PIKA_NANO_ENABLE
TEST(sysObj, getattr) {
char* lines =
"class Test:\n"
" def __init__(self):\n"
" self.a = 1\n"
"test = Test()\n"
"aa = getattr(test, 'a')\n";
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
obj_run(pikaMain, lines);
/* collect */
int aa = obj_getInt(pikaMain, "aa");
/* assert */
EXPECT_EQ(1, aa);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
#if !PIKA_NANO_ENABLE
TEST(sysObj, setattr) {
char* lines =
"class Test:\n"
"\n"
"test = Test()\n"
"setattr(test, 'a', 2)\n"
"aa = test.a\n";
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
obj_run(pikaMain, lines);
/* collect */
int aa = obj_getInt(pikaMain, "aa");
/* assert */
EXPECT_EQ(2, aa);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
#if !PIKA_NANO_ENABLE
TEST(sysobj, print_no_end) {
char* line = "print('test', end='')\n";
PikaObj* self = newRootObj("root", New_PikaStdLib_SysObj);
obj_run(self, line);
/* collect */
/* assert */
EXPECT_STREQ(log_buff[0], "test");
/* deinit */
obj_deinit(self);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
#if !PIKA_NANO_ENABLE
TEST(sysobj, print) {
char* line = "print(0, ['Hi'])\n";
PikaObj* self = newRootObj("root", New_PikaStdLib_SysObj);
obj_run(self, line);
/* collect */
/* assert */
EXPECT_STREQ(log_buff[0], "0 ['Hi']\r\n");
/* deinit */
obj_deinit(self);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(sysobj, print2) {
char* line = "print(0, ['Hi'], b'test')\n";
PikaObj* self = newRootObj("root", New_PikaStdLib_SysObj);
obj_run(self, line);
/* collect */
/* assert */
EXPECT_STREQ(log_buff[0], "0 ['Hi'] b'\\x74\\x65\\x73\\x74'\r\n");
/* deinit */
obj_deinit(self);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
TEST(sysobj, float_str) {
char* line = "float('1.1')\n";
PikaObj* self = newRootObj("root", New_PikaStdLib_SysObj);
obj_run(self, line);
/* collect */
/* assert */
EXPECT_STREQ(log_buff[0], "1.100000\r\n");
/* deinit */
obj_deinit(self);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_END

View File

@ -1,46 +0,0 @@
#include "test_common.h"
TEST_START
#if !PIKA_NANO_ENABLE && 1
TEST(thread, test1) {
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "test/python/_thread/test1.py");
/* clang-format on */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(thread, self) {
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
/* run */
__platform_printf("BEGIN\r\n");
pikaVM_runSingleFile(pikaMain, "test/python/_thread/thread_self.py");
/* clang-format on */
/* deinit */
obj_deinit(pikaMain);
EXPECT_STREQ(log_buff[0], "self._val: 2\r\n");
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_RUN_SINGLE_FILE(thread, test2, "test/python/_thread/test2.py")
TEST_RUN_SINGLE_FILE(eventloop, test1, "test/python/eventloop/test1.py")
TEST_RUN_SINGLE_FILE(eventloop, test2, "test/python/eventloop/test2.py")
TEST_RUN_SINGLE_FILE(eventloop, test3, "test/python/eventloop/test3.py")
TEST_RUN_SINGLE_FILE(eventloop, delay1, "test/python/eventloop/delay1.py")
TEST_RUN_SINGLE_FILE(eventloop, once1, "test/python/eventloop/once1.py")
TEST_RUN_SINGLE_FILE(eventloop, once2, "test/python/eventloop/once2.py")
#endif
TEST_END