diff options
Diffstat (limited to 'tests/projects')
21 files changed, 191 insertions, 10 deletions
diff --git a/tests/projects/c++/modules/stdmodules_deps_ordering/src/foo.cpp b/tests/projects/c++/modules/stdmodules_deps_ordering/src/foo.cpp new file mode 100644 index 000000000..5b9d1194e --- /dev/null +++ b/tests/projects/c++/modules/stdmodules_deps_ordering/src/foo.cpp @@ -0,0 +1,5 @@ +module foo; + +auto my_sum(int a, int b) -> int { + return a + b; +} diff --git a/tests/projects/c++/modules/stdmodules_deps_ordering/src/foo.mpp b/tests/projects/c++/modules/stdmodules_deps_ordering/src/foo.mpp new file mode 100644 index 000000000..4c9a649ca --- /dev/null +++ b/tests/projects/c++/modules/stdmodules_deps_ordering/src/foo.mpp @@ -0,0 +1,3 @@ +export module foo; + +export auto my_sum(int a, int b) -> int; diff --git a/tests/projects/c++/modules/stdmodules_deps_ordering/src/main.cpp b/tests/projects/c++/modules/stdmodules_deps_ordering/src/main.cpp new file mode 100644 index 000000000..1f87ceb59 --- /dev/null +++ b/tests/projects/c++/modules/stdmodules_deps_ordering/src/main.cpp @@ -0,0 +1,8 @@ +import foo; + +import std; + +int main() { + std::cout << my_sum(1, 2) << std::endl; + return 0; +} diff --git a/tests/projects/c++/modules/stdmodules_deps_ordering/test.lua b/tests/projects/c++/modules/stdmodules_deps_ordering/test.lua new file mode 100644 index 000000000..e77adc4ae --- /dev/null +++ b/tests/projects/c++/modules/stdmodules_deps_ordering/test.lua @@ -0,0 +1 @@ +inherit(".test_stdmodules") diff --git a/tests/projects/c++/modules/stdmodules_deps_ordering/xmake.lua b/tests/projects/c++/modules/stdmodules_deps_ordering/xmake.lua new file mode 100644 index 000000000..09c3f6a94 --- /dev/null +++ b/tests/projects/c++/modules/stdmodules_deps_ordering/xmake.lua @@ -0,0 +1,19 @@ +add_rules("mode.debug", "mode.release") +set_languages("c++latest") + +-- test that a plain c++ file is ordered after all the bmis it reuses from its deps, +-- not only after the last one +-- +-- @note foo must not import std, otherwise its bmi and the std bmi +-- would not be built by two distinct jobs of the foo target +-- +-- @see https://github.com/xmake-io/xmake/issues/7690 +target("foo") + set_kind("static") + add_files("src/foo.cpp") + add_files("src/foo.mpp", {public = true}) + +target("main") + set_kind("binary") + add_deps("foo") + add_files("src/main.cpp") diff --git a/tests/projects/embed/esp32/blink/boards/esp32c3/board.h b/tests/projects/embed/esp32/blink/boards/esp32c3/board.h new file mode 100644 index 000000000..126f2c2c3 --- /dev/null +++ b/tests/projects/embed/esp32/blink/boards/esp32c3/board.h @@ -0,0 +1,7 @@ +// the board configuration of esp32c3, it's selected by the `board` option +// +// @note gpio12-17 are the spi flash of the esp32c3, do not use them +// +#pragma once + +#define LED_GPIO 8 diff --git a/tests/projects/embed/esp32/blink/src/main.c b/tests/projects/embed/esp32/blink/src/main.c new file mode 100644 index 000000000..b51e3b67b --- /dev/null +++ b/tests/projects/embed/esp32/blink/src/main.c @@ -0,0 +1,26 @@ +// blink the led of the board and print a heartbeat +// +// the led pin comes from `boards/<board>/board.h`, it's selected by the board option, +// e.g. xmake f --board=esp32c3 +// +// @note the entry is the esp-idf native `void app_main(void)`, and we print with +// `esp_rom_printf`, it writes to the rom console, which is the usb port on the +// boards booting over the native usb (usb-serial-jtag), e.g. xmake monitor +// +#include "board.h" +#include "driver/gpio.h" +#include "esp_rom_sys.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +void app_main(void) +{ + esp_rom_printf("blink: toggle gpio %d every 500ms\n", LED_GPIO); + gpio_reset_pin(LED_GPIO); + gpio_set_direction(LED_GPIO, GPIO_MODE_OUTPUT); + for (int count = 0; ; count++) { + gpio_set_level(LED_GPIO, count & 1); + esp_rom_printf("blink: tick %d\n", count); + vTaskDelay(pdMS_TO_TICKS(500)); + } +} diff --git a/tests/projects/embed/esp32/blink/xmake-addons.lua b/tests/projects/embed/esp32/blink/xmake-addons.lua new file mode 100644 index 000000000..aea4ad480 --- /dev/null +++ b/tests/projects/embed/esp32/blink/xmake-addons.lua @@ -0,0 +1,2 @@ +-- the addon is installed automatically when we load this project +add_addons("esp32-devel") diff --git a/tests/projects/embed/esp32/blink/xmake.lua b/tests/projects/embed/esp32/blink/xmake.lua new file mode 100644 index 000000000..3fea2dd12 --- /dev/null +++ b/tests/projects/embed/esp32/blink/xmake.lua @@ -0,0 +1,15 @@ +-- the esp32 blink example, it needs the esp32-devel addon +-- +-- $ xmake f --board=esp32c3 +-- $ xmake +-- $ xmake install -- flash the image to the board +-- $ xmake run -- flash it and monitor the serial output +-- +includes("@addon/esp32-devel/board") + +target("blink") + add_rules("@addon/esp32-devel/app") + add_files("src/*.c") + + -- the led pin of the board, @see boards/<board>/board.h + add_includedirs("boards/" .. (get_config("board") or "esp32c3")) diff --git a/tests/projects/other/bin2c/src/asset.bin b/tests/projects/other/bin2c/src/asset.bin new file mode 100644 index 000000000..db1331f22 --- /dev/null +++ b/tests/projects/other/bin2c/src/asset.bin @@ -0,0 +1 @@ +hello transform!
\ No newline at end of file diff --git a/tests/projects/other/bin2c/src/asset2.bin b/tests/projects/other/bin2c/src/asset2.bin new file mode 100644 index 000000000..d7ffc4b96 --- /dev/null +++ b/tests/projects/other/bin2c/src/asset2.bin @@ -0,0 +1 @@ +hello luafile!
\ No newline at end of file diff --git a/tests/projects/other/bin2c/src/main.c b/tests/projects/other/bin2c/src/main.c index 74898132c..d85e9934e 100644 --- a/tests/projects/other/bin2c/src/main.c +++ b/tests/projects/other/bin2c/src/main.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdint.h> #include <ctype.h> +#include <string.h> static unsigned char g_bin_data[] = { #include "data.bin.h" @@ -10,6 +11,14 @@ static unsigned char g_ico_data[] = { #include "xmake.ico.h" }; +static unsigned char g_asset_data[] = { + #include "asset.bin.h" +}; + +static unsigned char g_asset2_data[] = { + #include "asset2.bin.h" +}; + static void hexdump(const char* name, const uint8_t* data, uint32_t size) { printf("%s: size: %u bytes\n", name, (unsigned int)size); if (size == 0) { @@ -94,5 +103,25 @@ int main(int argc, char** argv) hexdump("data.bin", g_bin_data, (uint32_t)sizeof(g_bin_data)); printf("\n"); hexdump("xmake.ico", g_ico_data, (uint32_t)sizeof(g_ico_data)); + printf("\n"); + hexdump("asset.bin (transformed)", g_asset_data, (uint32_t)sizeof(g_asset_data)); + printf("\n"); + hexdump("asset2.bin (transformed by lua file)", g_asset2_data, (uint32_t)sizeof(g_asset2_data)); + + // verify the function transform: asset.bin must be the reverse of "hello transform!" (+ zeroend '\0') + const char* expected = "!mrofsnart olleh"; + if (sizeof(g_asset_data) != 17 || memcmp(g_asset_data, expected, 16) != 0) { + printf("asset.bin: transform verification failed!\n"); + return 1; + } + printf("asset.bin: transform verification ok\n"); + + // verify the lua-file transform: asset2.bin must be the reverse of "hello luafile!" (+ zeroend '\0') + const char* expected2 = "!elifaul olleh"; + if (sizeof(g_asset2_data) != 15 || memcmp(g_asset2_data, expected2, 14) != 0) { + printf("asset2.bin: transform verification failed!\n"); + return 1; + } + printf("asset2.bin: transform verification ok\n"); return 0; } diff --git a/tests/projects/other/bin2c/test.lua b/tests/projects/other/bin2c/test.lua index b57362078..a23bb98a3 100644 --- a/tests/projects/other/bin2c/test.lua +++ b/tests/projects/other/bin2c/test.lua @@ -1,3 +1,5 @@ function main(t) t:build() + -- run the target, main.c verifies the transformed asset.bin and exits non-zero on mismatch + os.exec("xmake run test") end diff --git a/tests/projects/other/bin2c/transform.lua b/tests/projects/other/bin2c/transform.lua new file mode 100644 index 000000000..54cf1f394 --- /dev/null +++ b/tests/projects/other/bin2c/transform.lua @@ -0,0 +1,5 @@ +function main(inputfile, outputfile) + import("core.base.bytes") + local data = io.readfile(inputfile, {encoding = "binary"}) + io.writefile(outputfile, data:reverse(), {encoding = "binary"}) +end diff --git a/tests/projects/other/bin2c/xmake.lua b/tests/projects/other/bin2c/xmake.lua index b00dedb65..d60aea710 100644 --- a/tests/projects/other/bin2c/xmake.lua +++ b/tests/projects/other/bin2c/xmake.lua @@ -4,7 +4,15 @@ target("test") set_kind("binary") add_rules("utils.bin2c", {linewidth = 16, extensions = {".bin", ".ico"}}) add_files("src/*.c") - add_files("src/*.bin") + add_files("src/data.bin") add_files("src/xmake.ico", {nozeroend = true}) + add_files("src/asset.bin", {transform = function (inputfile, outputfile, opt) + import("core.base.bytes") + assert(bytes and opt.target) + local data = io.readfile(inputfile, {encoding = "binary"}) + io.writefile(outputfile, data:reverse(), {encoding = "binary"}) + end}) + -- transform can also be a lua script file (supported by the project generators) + add_files("src/asset2.bin", {transform = path.join(os.projectdir(), "transform.lua")}) diff --git a/tests/projects/other/bin2obj/src/asset.bin b/tests/projects/other/bin2obj/src/asset.bin new file mode 100644 index 000000000..db1331f22 --- /dev/null +++ b/tests/projects/other/bin2obj/src/asset.bin @@ -0,0 +1 @@ +hello transform!
\ No newline at end of file diff --git a/tests/projects/other/bin2obj/src/asset2.bin b/tests/projects/other/bin2obj/src/asset2.bin new file mode 100644 index 000000000..d7ffc4b96 --- /dev/null +++ b/tests/projects/other/bin2obj/src/asset2.bin @@ -0,0 +1 @@ +hello luafile!
\ No newline at end of file diff --git a/tests/projects/other/bin2obj/src/main.c b/tests/projects/other/bin2obj/src/main.c index bc1d2442f..03c50352d 100644 --- a/tests/projects/other/bin2obj/src/main.c +++ b/tests/projects/other/bin2obj/src/main.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdint.h> #include <ctype.h> +#include <string.h> extern const uint8_t _binary_data_bin_start[]; extern const uint8_t _binary_data_bin_end[]; @@ -8,30 +9,39 @@ extern const uint8_t _binary_data_bin_end[]; extern const uint8_t _binary_xmake_ico_start[]; extern const uint8_t _binary_xmake_ico_end[]; +extern const uint8_t _binary_asset_bin_start[]; +extern const uint8_t _binary_asset_bin_end[]; + +extern const uint8_t _binary_asset2_bin_start[]; +extern const uint8_t _binary_asset2_bin_end[]; + +extern const uint8_t _binary_asset2_bin_start[]; +extern const uint8_t _binary_asset2_bin_end[]; + static void hexdump(const char* name, const uint8_t* data, uint32_t size) { printf("%s: size: %u bytes\n", name, (unsigned int)size); if (size == 0) { return; } - + // if file is larger than 128 bytes, only dump first 64 and last 64 bytes uint32_t dump_size = size; uint32_t start_offset = 0; uint32_t end_offset = 0; uint32_t skip_size = 0; - + if (size > 128) { dump_size = 64; start_offset = 0; end_offset = size - 64; skip_size = end_offset - start_offset - dump_size; } - + // dump start for (uint32_t offset = start_offset; offset < start_offset + dump_size; offset += 16) { // print offset printf("%08x ", (unsigned int)offset); - + // print hex bytes (8 bytes, space, 8 bytes) for (uint32_t i = 0; i < 16; i++) { if (offset + i < size) { @@ -43,7 +53,7 @@ static void hexdump(const char* name, const uint8_t* data, uint32_t size) { printf(" "); } } - + // print ASCII representation printf(" |"); for (uint32_t i = 0; i < 16 && offset + i < size; i++) { @@ -52,18 +62,18 @@ static void hexdump(const char* name, const uint8_t* data, uint32_t size) { } printf("|\n"); } - + // print skip indicator if needed if (skip_size > 0) { printf(" ... (skipped %u bytes) ...\n", (unsigned int)skip_size); } - + // dump end if needed if (size > 128) { for (uint32_t offset = end_offset; offset < size; offset += 16) { // print offset printf("%08x ", (unsigned int)offset); - + // print hex bytes (8 bytes, space, 8 bytes) for (uint32_t i = 0; i < 16; i++) { if (offset + i < size) { @@ -75,7 +85,7 @@ static void hexdump(const char* name, const uint8_t* data, uint32_t size) { printf(" "); } } - + // print ASCII representation printf(" |"); for (uint32_t i = 0; i < 16 && offset + i < size; i++) { @@ -90,9 +100,31 @@ static void hexdump(const char* name, const uint8_t* data, uint32_t size) { int main(int argc, char** argv) { const uint32_t _binary_data_bin_size = (uint32_t)(_binary_data_bin_end - _binary_data_bin_start); const uint32_t _binary_xmake_ico_size = (uint32_t)(_binary_xmake_ico_end - _binary_xmake_ico_start); + const uint32_t _binary_asset_bin_size = (uint32_t)(_binary_asset_bin_end - _binary_asset_bin_start); + const uint32_t _binary_asset2_bin_size = (uint32_t)(_binary_asset2_bin_end - _binary_asset2_bin_start); hexdump("data.bin", _binary_data_bin_start, _binary_data_bin_size); printf("\n"); hexdump("xmake.ico", _binary_xmake_ico_start, _binary_xmake_ico_size); + printf("\n"); + hexdump("asset.bin (transformed)", _binary_asset_bin_start, _binary_asset_bin_size); + printf("\n"); + hexdump("asset2.bin (transformed by lua file)", _binary_asset2_bin_start, _binary_asset2_bin_size); + + // verify the function transform: asset.bin must be the reverse of "hello transform!" (+ zeroend '\0') + const char* expected = "!mrofsnart olleh"; + if (_binary_asset_bin_size != 17 || memcmp(_binary_asset_bin_start, expected, 16) != 0) { + printf("asset.bin: transform verification failed!\n"); + return 1; + } + printf("asset.bin: transform verification ok\n"); + + // verify the lua-file transform: asset2.bin must be the reverse of "hello luafile!" (+ zeroend '\0') + const char* expected2 = "!elifaul olleh"; + if (_binary_asset2_bin_size != 15 || memcmp(_binary_asset2_bin_start, expected2, 14) != 0) { + printf("asset2.bin: transform verification failed!\n"); + return 1; + } + printf("asset2.bin: transform verification ok\n"); return 0; } diff --git a/tests/projects/other/bin2obj/test.lua b/tests/projects/other/bin2obj/test.lua index 7f2050b62..a75aa7e40 100644 --- a/tests/projects/other/bin2obj/test.lua +++ b/tests/projects/other/bin2obj/test.lua @@ -1,4 +1,6 @@ function main(t) t:build() + -- run the target, main.c verifies the transformed asset.bin and exits non-zero on mismatch + os.exec("xmake run test") end diff --git a/tests/projects/other/bin2obj/transform.lua b/tests/projects/other/bin2obj/transform.lua new file mode 100644 index 000000000..54cf1f394 --- /dev/null +++ b/tests/projects/other/bin2obj/transform.lua @@ -0,0 +1,5 @@ +function main(inputfile, outputfile) + import("core.base.bytes") + local data = io.readfile(inputfile, {encoding = "binary"}) + io.writefile(outputfile, data:reverse(), {encoding = "binary"}) +end diff --git a/tests/projects/other/bin2obj/xmake.lua b/tests/projects/other/bin2obj/xmake.lua index 9541e17ae..d383bb1bb 100644 --- a/tests/projects/other/bin2obj/xmake.lua +++ b/tests/projects/other/bin2obj/xmake.lua @@ -6,3 +6,11 @@ target("test") add_files("src/*.c") add_files("src/data.bin", {zeroend = true}) add_files("src/xmake.ico", {zeroend = false}) + add_files("src/asset.bin", {zeroend = true, transform = function (inputfile, outputfile, opt) + import("core.base.bytes") + assert(bytes and opt.target) + local data = io.readfile(inputfile, {encoding = "binary"}) + io.writefile(outputfile, data:reverse(), {encoding = "binary"}) + end}) + -- transform can also be a lua script file (supported by the project generators) + add_files("src/asset2.bin", {zeroend = true, transform = path.join(os.projectdir(), "transform.lua")}) |
