Explorar el Código

Added script to conveniently run both HOST and QEMU test

Martin Valik hace 5 años
padre
commit
cdd723ff0f
Se han modificado 6 ficheros con 42 adiciones y 48 borrados
  1. 3 17
      .gitlab-ci.yml
  2. 3 1
      CMakeLists.txt
  3. 3 12
      test/README.md
  4. 1 1
      test/qemu_test.cpp
  5. 0 17
      test/run_qemu.sh
  6. 32 0
      test/run_test.sh

+ 3 - 17
.gitlab-ci.yml

@@ -56,20 +56,6 @@ run_tests:
     - internet
     - internet
   script:
   script:
     - cd $CI_PROJECT_DIR/test
     - cd $CI_PROJECT_DIR/test
-    - dd if=/dev/zero bs=1024 count=4096 of="empty_file.bin"
-
-    # Run QEMU in backround (deamonized)
-    - ${QEMU_PATH}
-      -daemonize
-      -machine esp32
-      -drive file=empty_file.bin,if=mtd,format=raw
-      -global driver=esp32.gpio,property=strap_mode,value=0x0f
-      -serial tcp::5555,server,nowait
-
-    - cd $CI_PROJECT_DIR/test && mkdir build && cd build
-
-    # Compile and run qemu tests
-    - cmake .. -DQEMU_TEST=True && make && ./serial_flasher_test
-
-    # Compile and run host tests
-    - cmake .. -DQEMU_TEST=False && make && ./serial_flasher_test
+    - export QEMU_PATH=/opt/qemu/bin/qemu-system-xtensa
+    - ./run_test.sh qemu
+    - ./run_test.sh host

+ 3 - 1
CMakeLists.txt

@@ -41,4 +41,6 @@ else()
 
 
 endif()
 endif()
 
 
-target_compile_definitions(${target} PUBLIC -DMD5_ENABLED=1)
+if(DEFINED MD5_ENABLED)
+    target_compile_definitions(${target} PRIVATE -DMD5_ENABLED=${MD5_ENABLED})
+endif()

+ 3 - 12
test/README.md

@@ -18,22 +18,13 @@ Please refer to [building qemu](https://github.com/espressif/qemu) for instructi
 
 
 ### Qemu test
 ### Qemu test
 
 
-Before running qemu tests, qemu itself has to be launched first. 
-
-QEMU_PATH environment variable pointing to qemu-system-xtensa has to be defined.
+QEMU_PATH environment variable pointing to compiled `qemu/build/xtensa-softmmu/qemu-system-xtensa` has to be defined.
 ```
 ```
 export QEMU_PATH=path_to_qemu-system-xtensa
 export QEMU_PATH=path_to_qemu-system-xtensa
-sh run_qemu.sh
-```
-
-Run qemu test
-```
-cmake .. -DQEMU_TEST=True && cmake --build . && ./serial_flasher_test
+./run_test.sh qemu
 ```
 ```
 
 
 ### Host test
 ### Host test
-
-Run host test
 ```
 ```
-cmake .. -DQEMU_TEST=False && cmake --build . && ./serial_flasher_test
+./run_test.sh host
 ```
 ```

+ 1 - 1
test/qemu_test.cpp

@@ -91,7 +91,7 @@ TEST_CASE( "Can write application to flash" )
     ifstream qemu_image;
     ifstream qemu_image;
 
 
     new_image.open ("../hello-world.bin", ios::binary | ios::in);
     new_image.open ("../hello-world.bin", ios::binary | ios::in);
-    qemu_image.open ("../empty_file.bin", ios::binary | ios::in);
+    qemu_image.open ("empty_file.bin", ios::binary | ios::in);
 
 
     REQUIRE ( new_image.is_open() );
     REQUIRE ( new_image.is_open() );
     REQUIRE ( qemu_image.is_open() );
     REQUIRE ( qemu_image.is_open() );

+ 0 - 17
test/run_qemu.sh

@@ -1,17 +0,0 @@
-
-# QEMU_PATH environment variable has to be defined, pointing to qemu-system-xtensa
-# Example: export QEMU_PATH=/home/user/esp/qemu/xtensa-softmmu/qemu-system-xtensa
-if [ -z "${QEMU_PATH}" ]; then
-    echo "QEMU_PATH environment variable needs to be set"
-    exit 1
-fi
-
-# generate empty file into which application will be flashed and compared against.
-dd if=/dev/zero bs=1024 count=4096 of="empty_file.bin"
-
-${QEMU_PATH} \
-    -nographic \
-    -machine esp32 \
-    -drive file=empty_file.bin,if=mtd,format=raw \
-    -global driver=esp32.gpio,property=strap_mode,value=0x0f \
-    -serial tcp::5555,server,nowait

+ 32 - 0
test/run_test.sh

@@ -0,0 +1,32 @@
+#!/bin/bash
+
+mkdir -p build && cd build
+
+if [ "$1" = "host" ]; then
+    cmake -DQEMU_TEST=False .. && cmake --build . && ./serial_flasher_test
+elif [ "$1" = "qemu" ]; then
+    # QEMU_PATH environment variable has to be defined, pointing to qemu-system-xtensa
+    # Example: export QEMU_PATH=/home/user/esp/qemu/xtensa-softmmu/qemu-system-xtensa
+    if [ -z "${QEMU_PATH}" ]; then
+        echo "QEMU_PATH environment variable needs to be set"
+        exit 1
+    fi
+
+    # Generate empty file into which application will be flashed and compared against
+    dd if=/dev/zero bs=1024 count=4096 of="empty_file.bin"
+
+    # Run qemu in background (daemonized)
+    ${QEMU_PATH} \
+        -daemonize \
+        -machine esp32 \
+        -drive file=empty_file.bin,if=mtd,format=raw \
+        -global driver=esp32.gpio,property=strap_mode,value=0x0f \
+        -serial tcp::5555,server,nowait
+
+    cmake -DQEMU_TEST=True .. && cmake --build . && ./serial_flasher_test
+
+    # Kill qemu process running in background
+    kill -9 $(pidof qemu-system-xtensa)
+else
+    echo "Please select which test to run: qemu or host"
+fi