README.md
1
2# GUIX and GUIX Studio Regression Test Guide
3## Introduction
4This guide provides instructions on how to run and add GUIX and GUIX Studio regression tests, along with effective debugging techniques for failed test cases. Regression testing is essential for ensuring that new code changes do not introduce new bugs or regressions. By following the steps outlined in this guide, you can contribute to maintaining a stable and reliable codebase.
5
6## Table of Contents
71. [GUIX Regression Test](#guix-regression-test)
8 1. [Directory Structure](#directory-structure)
9 2. [Types of Test Cases](#types-of-test-cases)
10 3. [Prerequisites](#prerequisites)
11 4. [Run Regression Test](#run-regression-test)
12 5. [Run One Test Case](#run-one-test-case)
13 6. [Debug Failed Test](#debug-failed-test)
14 7. [Add New Test](#add-new-test)
15 8. [Add New Build Type](#add-new-build-type)
162. [GUIX Studio Regression Test](#guix-studio-regression-test)
17 1. [Directory Structure](#directory-structure-1)
18 2. [GUIX Studio Test Demo](#guix-studio-test-demo)
19 1. [Run GUIX Studio Test Demo](#run-guix-studio-test-demo)
20 2. [Debug Failed Test](#debug-failed-test)
21 3. [Add New Test Case](#add-new-test-case)
22 3. [GUIX Studio Test View](#guix-studio-test-view)
23 1. [Architecture](#architecture)
24 2. [Run GUIX Studio Test View](#run-guix-studio-test-view)
25 3. [Debug Failed Test](#debug-failed-test-1)
26 4. [Add New Test Case](#add-new-test-case-1)
27
28## GUIX Regression Test
29
30### Directory Structure
31
32The GUIX regression test is built on top of the CMake build system and organize its code in `test\guix_test `folder. The foundational elements are structured as follows:
33- **cmake\CMakeLists.txt:** The CMake file that defines the build types and the test suites.
34- **cmake\regression\CMakeLists.txt:** The CMake file that defines the test cases for each test suite.
35- **coverage.sh:** The script that generates the coverage report.
36- **run.sh:** The script that builds and runs the tests.
37- **display_driver:** This directory hosts the display drivers used by the tests.
38- **golden_files:** This directory contains golden files used for verification during the tests, aiding in the comparison of expected and actual outcomes.
39- **regression_test\tests:** This directory contains the all GUIX regression tests.
40- **regression_test\utility:** This directory hosts utility files used by the regression test.
41- **regression_test\gx_show_canvas.exe:** A tool that displays GUIX canvas data that stored in a binary file.
42
43### Types of Test Cases
44
451. **Test case with output:**
46- In the generation mode, after each test point, a specified area of the GUIX canvas is saved to a binary file named `<test_name>.bin`.
47- A checksum value, calculated based on the canvas data, is saved to a file named `<test_name>.checksum`.
48- The binary file is used for checking the correctness of the test case visually.
49- The checksum file enables faster verification during tests by comparing expected and actual checksum values.
50
512. **Test case without output:**
52- In this type of test code, the test code typically checks the API return status or the values of a variable to verify the correctness of the test case.
53
54### Prerequisites
551. Linux environment.
562. Clone the GUIX repository.
573. Install required packages using script `install.sh` located in the `scripts` directory.
58
59### Run Regression Test
601. Navigate to the `test\guix_test\cmake` directory.
61
622. To build and run all the tests, use the following commands.
63```bash
64./run.sh build all
65./run.sh run all
66```
67
683. To build and run a specific test suite, use the following commands.
69```bash
70./run.sh build <build_type>
71./run.sh run <build_type>
72```
73
74The available build types are as follows:
75
76|Build Types|Description|Build Configuration Settings|
77|--------------|-----------|----------------------------|
78|default_build_coverage|Build with default configuration settings and generate coverage report|N/A|
79|disable_error_checking_build|Build with error checking disabled|*GX_DISABLE_ERROR_CHECKING*|
80|no_utf8_build_coverage|Build with UTF-8 support disabled and generate coverage report|GX_DISABLE_UTF8_SUPPORT and GX_DISABLE_ERROR_CHECKING|
81|no_utf8_no_checking_build|Build with UTF-8 support disabled and error checking disabled|GX_DISABLE_UTF8_SUPPORT and GX_DISABLE_ERROR_CHECKING|
82|ex_unicode_build|Build with extended Unicode support|GX_EXTENDED_UNICODE_SUPPORT|
83|ex_unicode_no_checking_build|Build with extended Unicode support and error checking disabled|GX_EXTENDED_UNICODE_SUPPORT and GX_DISABLE_ERROR_CHECKING|
84|mouse_support_build|Build with mouse support|GX_MOUSE_SUPPORT|
85|font_kerning_support_build|Build with font kerning support|GX_FONT_KERNING_SUPPORT|
86|dynamic_bidi_text_build|Build with dynamic bi-directional text support|GX_DYNAMIC_BIDI_TEXT_SUPPORT and GX_DYNAMIC_ARABIC_SHAPING_SUPPORT|
87|dynamic_bidi_text_no_checking_build|Build with dynamic bi-directional text support and error checking disabled|GX_DYNAMIC_BIDI_TEXT_SUPPORT, GX_DYNAMIC_ARABIC_SHAPING_SUPPORT and GX_DISABLE_ERROR_CHECKING|
88|_5_4_0_compatible_no_checking_build|Build with GUIX library version 5.4.0 compatibility and error checking disabled|GX_DISABLE_ERROR_CHECKING and GUIX_5_4_0_COMPATIBILITY|
89|synergy_font_support_build|Build with synergy font support|GX_SYNERGY_FONT_FORMAT_SUPPORT|
90|thai_glyph_shaping_support_build|Build with Thai glyph shaping support|GX_THAI_GLYPH_SHAPING_SUPPORT|
91|palette_mode_aa_text_colors_16_build|Build with palette mode with 16 colors for text drawing support|GX_PALETTE_MODE_AA_TEXT_COLORS=16|
92|disable_deprecated_string_api_build|Build with deprecated string API disabled|GX_DISABLE_DEPRECATED_STRING_API|
93|partial_canvas_support_build|Build with partial canvas support|GX_ENABLE_CANVAS_PARTIAL_FRAME_BUFFER|
94|partial_canvas_support_vertical_refresh_build|Build with partial canvas support and vertical refresh|GX_ENABLE_CANVAS_PARTIAL_FRAME_BUFFER and GX_CANVAS_REFRESH_DIRECTION_VERTICAL|
95|partial_canvas_support_horizontal_refresh_build|Build with partial canvas support and horizontal refresh|GX_ENABLE_CANVAS_PARTIAL_FRAME_BUFFER and GX_CANVAS_REFRESH_DIRECTION_HORIZONTAL|
96|||
97
98The **test reports** for each build type will be generated in the `test\guix_test\cmake\build\<build_type>` directory.
99
100The **coverage report** for `default_build_covearge` and `no_utf8_build_coverage` will be generated in the `test\guix_test\cmake\coverage_report` directory. For other build types, no coverage report is generated.
101
102### Run One Test Case
103
104Follow these steps to execute an individual test case:
105
1061. Build the test using the instructions provided in the previous section.
1072. Navigate to the `test\guix_test\cmake\build\<build_type>\regression` directory, where the test executables are generated.
108
1093. Run the test without output, where the test name is ended with `no_output`.
110```bash
111./<test_name>
112```
113
1144. Run other tests with checksum verification and specify the golden files path with the following command.
115```bash
116 ./<test_name> -checksum -gpath ../../../../golden_files/
117 ```
118
119### Debug Failed Test
120
121- Debugging with cgdb.
1221. Navigate to the `test\guix_test\cmake\build\<build_type>\regression` directory, where the test executables are generated. Start cgdb using the following command.
123```bash
124cgdb <test_name>
125```
126
1272. Set configuration parameter `-r` to run test without comparison.
128```bash
129set args -r
130```
131
1323. Set breakpoints as needed and run the test.
133
134- Debugging by comparing output files.
1351. Navigate to the `test\guix_test\cmake\build\<build_type>\regression\output_files` directory, where the failed output binary file is generated. The generated binary file is named `<test_name>_failures.bin`.
136
1372. Use **gx_show_canvas.exe** located in `test\guix_test\regression_test` to display the content in the failed output binary file. Compare it with the corresponding golden file located in the `test\guix_test\golden_files` directory. For the usage of **gx_show_canvas.exe**, please refer to **gx_show_canvas.md**.
138
139
140
141### Add New Test
142
143Follow these steps to add a new test:
1441. Create Win32 Demo Project.
145- Generate a Win32 demo project under the `test\example_internal` directory.
146- Ensure the main source file is named as `demo_guix_<example_name>.c`.
147
1482. Add Test Source File:
149- Place the test source file in the `test\guix_test\regression_test\tests` directory.
150- Name the test file start with `validation_guix`.
151
1523. Implement the Test Case:
153- In the test source file, include the necessary header files:
154```c
155#include <stdio.h>
156#include "tx_api.h"
157#include "gx_api.h"
158#include "gx_validation_utility.h"
159```
160
161- Set test parameters:
162```c
163TEST_PARAM test_parameter = {
164 "", /* Test name */
165 0, 0, 0, 0 /* Define the coordinates of the capture area.*/
166};
167```
168
169Definition of the TEST_PARAM structure:
170```c
171typedef struct TEST_PARAM_S
172{
173
174 char *test_name; /* Must be set */
175
176
177 /* The following parameters defines the screen area to capture.
178 If 0, capture the whole screen. */
179
180 int x_start;
181 int y_start;
182 int x_end;
183 int y_end;
184} TEST_PARAM;
185```
186
187- Define the main function:
188```c
189int main(int argc, char ** argv)
190{
191 /* Start ThreadX system */
192 tx_kernel_enter();
193 return(0);
194}
195```
196
197- Create the test thread:
198```c
199static VOID control_thread_entry(ULONG);
200
201VOID tx_application_define(void *first_unused_memory)
202{
203 gx_validation_application_define(first_unused_memory);
204
205 /* Termiante the test if it runs for more than 100 ticks */
206 /* This function is not implemented yet. */
207 gx_validation_watchdog_create(100);
208
209 /* Create a dedicated thread to perform various operations
210 on the line drawing example. These operations simulate
211 user input. */
212 gx_validation_control_thread_create(control_thread_entry);
213}
214```
215
216- Include the test example source code:
217```c
218#ifdef WIN32
219#undef WIN32
220#endif
221
222#include "gx_validation_wrapper.h"
223#include "demo_guix_<example_name>.c"
224```
225
226The test example source code also contains a main function, The header file `gx_validation_wrapper.h` is used to replace the main function in the test example source code.
227
228- Thread entry example for test case without output:
229```c
230static VOID control_thread_entry(ULONG input)
231{
232int failed_tests = 0;
233UINT status;
234GX_PROMPT *prompt = &button_screen.button_screen_title_1;
235GX_CONST GX_CHAR *text;
236
237 gx_widget_hide(&button_screen);
238
239 status = gx_prompt_text_get(prompt, &text);
240 EXPECT_EQ(GX_INVALID_CANVAS, status);
241
242 if(failed_tests == 0)
243 {
244 gx_validation_print_test_result(TEST_SUCCESS);
245 exit(0);
246 }
247 else
248 {
249 gx_validation_print_test_result(TEST_FAIL);
250 exit(1);
251 }
252}
253```
254
255- Thread entry example for test case with output:
256```c
257static VOID control_thread_entry(ULONG input)
258{
259int frame_id = 1;
260GX_EVENT my_event;
261
262 memset(&my_event, 0, sizeof(GX_EVENT));
263 my_event.gx_event_display_handle = 1;
264
265 gx_validation_set_frame_id(frame_id++);
266 gx_validation_set_frame_comment("Initialize the screen.");
267 gx_validation_screen_refresh();
268
269 /* Simulate a pen down event. */
270 my_event.gx_event_type = GX_EVENT_PEN_DOWN;
271 my_event.gx_event_payload.gx_event_pointdata.gx_point_x = 207;
272 my_event.gx_event_payload.gx_event_pointdata.gx_point_y = 376;
273 gx_system_event_send(&my_event);
274
275 /* Simulate a pen up event. */
276 my_event.gx_event_type = GX_EVENT_PEN_UP;
277 gx_system_event_send(&my_event);
278
279 /* Force a screen refresh to capture the canvas data or compare the checksum. */
280 gx_validation_set_frame_id(frame_id++);
281 gx_validation_set_frame_comment("Scroll the vertical list.");
282 gx_validation_screen_refresh();
283
284 /* Signal the end of the test case. Verify the output. */
285 gx_validation_end();
286
287 exit(0);
288}
289```
290
2914. Add Test Case to GUIX Regression Test System:
292- Open the `test\guix_test\cmake\regression\CMakeLists.txt` file.
293- Add test demo project to the appropriate demo list based on the demo build configuration settings. The available types of demo lists are as follows:
294
295| Types of Demo Lists |Description | Build Configuration Settings |
296| ------------------- | ------------------------------ | ---------------------------- |
297| NO_UTF8_DEMOS |Demos that do not support UTF-8 | GX_DISABLE_UT8_SUPPORT |
298| EXTENDED_UNICODE_DEMOS |Demos that support extended Unicode | GX_EXTENDED_UNICODE_SUPPORT |
299| OTHER_DEMOS | Demos with default configuration settings | N/A |
300| MOUSE_SUPPORT_DEMOS | Demos support mouse input | GX_MOUSE_SUPPORT |
301| FONT_KERNING_SUPPORT_DEMOS | Demos support font kerning | GX_FONT_KERNING_SUPPORT |
302| DYNAMIC_BIDI_TEXT_DEMOS | Demos support dynamic bi-directional text | GX_DYNAMIC_BIDI_TEXT_SUPPORT and GX_DYNAMIC_ARABIC_SHAPING_SUPPORT |
303| _5_4_0_COMPATIBLE_DEMOS | Demos that compatible with GUIX library version 5.4.0 | GUIX_5_4_0_COMPATIBILITY |
304| SYNERGY_FONT_SUPPORT_DEMOS | Demos that support synergy font | GX_SYNERGY_FONT_FORMAT_SUPPORT |
305| THAI_GLYPH_SHAPING_SUPPORT_DEMOS | Demos that support Thai glyph shaping | GX_THAI_GLYPH_SHAPING_SUPPORT |
306| PALETTE_MODE_AA_TEXT_COLORS_16_DEMOS | Demos that support palette mode with 16 colors for text drawing | GX_PALETTE_MODE_AA_TEXT_COLORS=16 |
307| PARTIAL_CANVAS_SUPPORT_DEMOS | Demos that support partial canvas | GX_ENABLE_CANVAS_PARTIAL_FRAME_BUFFER |
308
309- Define demo project file list:
310```c
311set(<example_name>_FILE_LIST
312 demo_guix_<example_name>.c
313 ...)
314```
315
316- Define test case for demo project:
317```c
318set(<example_name>_REG_TESTS
319 <test_name>
320 ...)
321```
322
3235. Generate Golden Files:
324- Build GUIX regression test with the appropriate build type based on the demo build configuration settings.
325
326- Generate golden files for the test case. If the test has no output, this step can be skipped.
327 - Navigate to the `test\guix_test\cmake\build\<build_type>\regression` directory, where the test executables are generated.
328
329 - Generate output files for the test case with the following command.
330 ```bash
331 ./<test_name> -r -generate
332 ```
333 After the command is executed, the output binary file `<test_name>.bin` and checksum file `<test_name>.checksum` will be generated in the `test\guix_test\cmake\build\<build_type>\regression\output_files` directory.
334
335 - Verify the correctness of the test by checking the content of the output binary file `<test_name>.bin` with the **gx_show_canvas.exe** tool located in `test\guix_test\regression_test`.
336
337 - Compress the output binary file `<test_name>.bin` into a 7z file with the following command.
338 ```bash
339 7z a <test_name>.7z <test_name>.bin
340 ```
341
342 - Copy the 7z file `<test_name>.7z` and `<test_name>.checksum` to the `test\guix_test\golden_files` directory.
343
344- Run the GUIX regression test to see if the test case passes.
345
346- Now the test case is ready to be submitted to the GUIX repository.
347
348### Add New Build Type
349
350If the available build types lack the configuration settings required for your test, you can add a new build type by following these steps:
351
3521. Open the `test\guix_test\cmake\CMakeLists.txt` file.
3532. Add a new build type using the following example:
354```cmake
355set(disable_error_checking_build -DGX_DISABLE_ERROR_CHECKING)
356```
3573. Include the new build type in the `BUILD_CONFIGURATIONS` list.
358```cmake
359set(BUILD_CONFIGURATIONS
360...
361 <new_build_type>
362)
363```
364
3654. Add the new demo type.
366- Open the `test\guix_test\cmake\regression\CMakeLists.txt` file.
367- Define a new demo type list and add the new example project to it:
368```cmake
369set (<demo_type_name> <example_name>)
370```
371
372- Set the directory path for the new demos by updating the existing logic:
373```cmake
374set(EXAMPLE_INTERNAL_DIR ${ROOT_DIR}/example_internal)
375foreach(
376 demo
377...
378 ${<demo_type_name>};
379...
380 set(${demo}_SOURCE_DIRECTORY ${EXAMPLE_INTERNAL_DIR}/${demo})
381endforeach()
382```
383
384- Update the existing logic to set the `demos` variable according to the build type. This variable will later be used to add test cases for the build type:
385```cmake
386...
387elseif("-D<new_build_configuration>" IN_LIST ${CMAKE_BUILD_TYPE})
388 set(demos ${<demo_type_name>})
389...
390```
391
392- Update existing logic to set regression test program's SOURCE as `validation_*.c` and related source files, excluding `demo_*` for the test cases of the new demo type:
393```cmake
394# Set regression test program's SOURCE as validation_*.c and related source
395# files excluding demo_*
396foreach(
397 demo
398...
399 ${<demo_type_name>};
400...
401endforeach()
402```
403
404## GUIX Studio Regression Test
405
406### Prerequisites
4071. Windows environment.
4082. Clone the GUIX repository.
4093. Install Python 3.0 or later.
4104. Install Visual Studio 2019.
411
412### GUIX Studio Test Demo
413
414The demo tests are located in the `test\guix_studio_test\test_demo` directory.
415
416Target Directories: `examples`, `tutorials` and `test\example_internal`.
417
418#### Run GUIX Studio Test Demo
4191. Open developer command prompt for Visual Studio 2019.
4202. Navigate to the `test\guix_studio_test\test_demo` directory.
4213. To verify the output files for the `gxp` projects under the target directories, run the following command.
422```python
423test_main.py -b -t
424```
425- `-b` option is used to build the latest GUIX Studio executable.
426- `-t` option is used to verify the output files for the `gxp` projects under the target directories.
427
4284. To test the compilation of the Visual Studio project under the target directories, run the following command.
429```python
430test_main.py --compile_project
431```
432
4335. To regenerate output files for the `gxp` projects under the target directories, run the following command.
434```python
435test_main.py -b -g
436```
437
4386. To upgrade project version to the latest for the `gxp` projects under the target directories, run the following command.
439```python
440test_main.py --update_gxp_project
441```
442
4437. To set GUIX library version for the `gxp` projects under the target directories, run the following command.
444```python
445test_main.py -v <VERSION>
446```
447replace `<VERSION>` with the actual GUIX library version. such as `6.2.0`.
448
449#### Debug Failed Test
450
451After test execution, a test log file named `output_files_test_log.txt` will be generated in the current directory. If a test case failed, the log file provides detailed information about the failure.
452
453#### Add New Test Case
454
455If you have added a new `gxp` project under the target directories, this project will be automatically added to the test system. However, if your project involves the generation of binary files or other output files requiring verification, it is necessary to develop project-specific resource output logic. For guidance, you can consult the implementation of functions such as `test_utils::test_one_project()` and `test_utils.generate()`.
456
457
458### GUIX Studio Test View
459
460The test view tests are located in the `test\guix_studio_test\test_view` directory.
461
462#### Architecture
463![GUIX Studio Test View Architecture](guix_studio_test_view_architecture.png)
464*Figure 1: GUIX Studio Test View Architecture*
465
466GUIX Studio provides a test message handler for each function component, enabling interaction with the GUIX Studio Test View, a Python based test application that communicates with GUIX Studio by transmitting messages through these handlers. The `test_utils.py` module facilitates the sending of messages to individual function components within GUIX Studio. Utilizing these functions allows you to simulate user actions for the purpose of testing GUIX Studio. For example, you can use `test_utils::open_project()` to open a project in GUIX Studio.
467
468GUIX Studio Test View verifies the correctness of the test through two aspects:
4691. Comparing the checksum of the canvas data with the corresponding value stored in the golden files. The `test_utils.py` module includes the `test_utils::compare_result()` function, which facilitates this comparison process. In test mode, it checks the checksum of the canvas data against the correct value in the golden files. In generation mode, the function generates checksum values and stores them in the specified golden file.
470
4712. Comparing the output files of the testing `gxp` project with the corresponding files stored in the `golden_files` directory. the `test_utils.py` module includes the `test_utils::cmp_output_files()` function, which facilitates this comparison process.
472
473#### Run GUIX Studio Test View
4741. Open developer command prompt for Visual Studio 2019.
4752. Navigate to the `test\guix_studio_test\test_view` directory.
4763. Run the entire test with the following command.
477```python
478test_main.py -b
479```
4804. Run a specific test by specifying its name with the following command.
481```python
482test_main.py -b <test_name>
483```
484
485To explore the available test cases and obtain more information, use the following command to display the help message:
486```python
487test_main.py -h
488```
489
490#### Debug Failed Test
491After test execution, a test log file named `studio_view_test_log.txt` will be generated in the current directory. If a test case failed, the log file provides detailed information about the failure. If the test fails due to canvas data mismatch, a `test_failure` folder is generated in the current directory, which contains the screenshot of the failed test case.
492
493#### Add New Test Case
4941. Add a new test file.
4952. Import the necessary modules.
496```python
497import os
498import sys
499import time
500import test_utils
501import test_constants
502```
503
5043. Define test header for the test information.
505```python
506def get_test_header():
507 notes = "* <Test Name> *\n"
508 notes += "* *\n"
509 ...
510 return notes
511```
512
5134. Define test case.
514```python
515def <test_name>(generate, screenshot):
516 test_utils.output_test_header(get_test_header())
517 test_utils.setup(generate, screenshot, <golden_file_name>)
518
519 # Test code goes here.
520
521 test_utils.write_end(<test_name>)
522```
523
5245. Import the new test case to `test_main.py`.
525
526- Import the new test module:
527```python
528from <test_file_name> import <test_name>
529```
530
531- Add argument for the new test case:
532```python
533parser.add_argument('--<test_name>', action='store_true', dest='<test_name>' help='Run <test_name> test')
534```
535
536- Update existing logic to set the new test case to run when the user doesn't specify tests to run:
537```python
538if (... and
539 args.<test_name> is False):
540 ...
541 test_utils.<test_name> = True
542 ...
543```
544
545- Add logic to run test case:
546```python
547if test_utils.<test_name>:
548 <test_name>(args.generate, args.screenshot)
549```
550
551- Generate golden files for the new test case:
552```python
553test_main.py -b --<test_name> -g
554```
555
556- Copy the golden files to the `test\guix_studio_test\golden_files` directory.
557- Run the new test case to see if it passes.
558```python
559test_main.py -b --<test_name>
560```
561- Now the test case is ready to be submitted to the GUIX repository.