2022-06-05 23:01:17 +08:00
|
|
|
#include "test_common.h"
|
|
|
|
|
2022-07-11 03:14:14 +00:00
|
|
|
#if PIKA_SYNTAX_IMPORT_EX_ENABLE
|
2022-06-05 23:01:17 +08:00
|
|
|
TEST(module, cmodule_import) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
2022-06-05 23:07:45 +08:00
|
|
|
__platform_printf("BEGIN\r\n");
|
2022-06-05 23:01:17 +08:00
|
|
|
/* run */
|
|
|
|
obj_run(pikaMain,
|
2022-06-05 23:07:45 +08:00
|
|
|
"from TemplateDevice import qqee\n"
|
|
|
|
"mytime = qqee()\n");
|
2022-06-05 23:01:17 +08:00
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
/* deinit */
|
2022-06-05 23:07:45 +08:00
|
|
|
EXPECT_STREQ("NameError: name 'TemplateDevice.qqee' is not defined\r\n",
|
2022-06-06 14:45:37 +08:00
|
|
|
log_buff[5]);
|
2022-06-07 17:34:19 +08:00
|
|
|
EXPECT_STREQ("NameError: name 'qqee' is not defined\r\n", log_buff[2]);
|
2022-06-05 23:01:17 +08:00
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-06-06 14:45:37 +08:00
|
|
|
}
|
2022-06-27 11:29:48 +08:00
|
|
|
#endif
|
2022-06-07 17:34:19 +08:00
|
|
|
|
|
|
|
TEST(module, while_loop) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
extern unsigned char pikaModules_py_a[];
|
|
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
/* run */
|
|
|
|
obj_run(pikaMain,
|
|
|
|
"import test_module1\n"
|
|
|
|
"test_module1.while_loop()\n");
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ("4\r\n", log_buff[0]);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(module, for_loop) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
extern unsigned char pikaModules_py_a[];
|
|
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
/* run */
|
|
|
|
obj_run(pikaMain,
|
|
|
|
"import test_module1\n"
|
|
|
|
"test_module1.for_loop()\n");
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
2022-06-08 10:00:54 +08:00
|
|
|
EXPECT_STREQ("9\r\n", log_buff[0]);
|
2022-06-07 17:34:19 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-06-08 11:29:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(module, script) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
extern unsigned char pikaModules_py_a[];
|
|
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
/* run */
|
|
|
|
obj_run(pikaMain, "import test_module4\n");
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ("imported test moulde4\r\n", log_buff[0]);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-06-15 06:20:34 +00:00
|
|
|
|
|
|
|
TEST(module, __init__) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
extern unsigned char pikaModules_py_a[];
|
|
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
/* run */
|
|
|
|
obj_run(pikaMain, "import GTestTask\n");
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(obj_getInt(pikaMain, "GTestTask.testval"), 8848);
|
2022-06-15 14:49:17 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "BEGIN\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
2022-07-11 03:14:14 +00:00
|
|
|
#if PIKA_SYNTAX_IMPORT_EX_ENABLE
|
2022-06-15 14:49:17 +08:00
|
|
|
TEST(module, __init__2) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
extern unsigned char pikaModules_py_a[];
|
|
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
/* run */
|
|
|
|
obj_run(pikaMain, "import GTestTask as task\n");
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_EQ(obj_getInt(pikaMain, "task.testval"), 8848);
|
|
|
|
EXPECT_STREQ(log_buff[0], "BEGIN\r\n");
|
2022-06-15 06:20:34 +00:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-06-27 11:29:48 +08:00
|
|
|
#endif
|
2022-06-28 16:35:00 +08:00
|
|
|
|
2022-07-11 03:14:14 +00:00
|
|
|
#if PIKA_SYNTAX_IMPORT_EX_ENABLE
|
2022-06-28 16:35:00 +08:00
|
|
|
TEST(module, import_as_issue1) {
|
|
|
|
/* init */
|
|
|
|
pikaMemInfo.heapUsedMax = 0;
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
extern unsigned char pikaModules_py_a[];
|
|
|
|
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
|
|
|
__platform_printf("BEGIN\r\n");
|
|
|
|
/* run */
|
|
|
|
obj_run(pikaMain,
|
|
|
|
"import import_test as my_import\n"
|
|
|
|
"print(my_import.func())\n"
|
|
|
|
"print(import_test.func())\n");
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
EXPECT_STREQ(log_buff[0], "hello\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "hello\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[2], "BEGIN\r\n");
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-08-06 23:26:04 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if PIKA_SYNTAX_LEVEL==PIKA_SYNTAX_LEVEL_MAXIMAL
|
|
|
|
TEST(unittest, test1) {
|
|
|
|
/* init */
|
|
|
|
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/unittest/test1.py");
|
|
|
|
/* collect */
|
|
|
|
/* assert */
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
#endif
|