EmuFlight icon indicating copy to clipboard operation
EmuFlight copied to clipboard

WIP: Fixing unittests

Open Igorshp opened this issue 4 years ago • 15 comments

Trying to get the testsuite to run.

Will be updating this PR over time.

Help is much appreciated.

To run the tests:

make test

you may need to have clang, llvm and libblocksruntime-dev installed

Status

  • ✅ alignsensor_unittest.cc
  • ✅ arming_prevention_unittest.cc
  • ✅ atomic_unittest.cc
  • ✅ baro_bmp280_unittest.cc
  • ✅ baro_ms5611_unittest.cc
  • ✅ blackbox_encoding_unittest.cc
  • ✅ blackbox_unittest.cc
  • ✅ cli_unittest.cc
  • ✅ cms_unittest.cc
  • ✅ common_filter_unittest.cc
  • ✅ encoding_unittest.cc
  • ✅ flight_failsafe_unittest.cc
  • ✅ flight_imu_unittest.cc
  • ✅ gps_conversion_unittest.cc
  • ✅ huffman_unittest.cc
  • ✅ io_serial_unittest.cc
  • ✅ ledstrip_unittest.cc
  • ✅ maths_unittest.cc
  • ✅ osd_unittest.cc
  • ✅ pg_unittest.cc
  • ✅ pid_unittest.cc (test itself fails ❌ )
  • ✅ rc_controls_unittest.cc
  • ✅ rcdevice_unittest.cc
  • ✅ rx_crsf_unittest.cc (test itself fails ❌ )
  • ✅ rx_ibus_unittest.cc
  • ✅ rx_ranges_unittest.cc
  • ✅ rx_rx_unittest.cc
  • ✅ scheduler_unittest.cc
  • ❌ sensor_gyro_unittest.cc (requires arm_math.h library)
  • ✅ telemetry_crsf_msp_unittest.cc
  • ✅ telemetry_crsf_unittest.cc (test itself fails ❌ )
  • ✅ telemetry_hott_unittest.cc
  • ✅ telemetry_ibus_unittest.cc
  • ✅ transponder_ir_unittest.cc
  • ✅ vtx_unittest.cc (fixed in https://github.com/emuflight/EmuFlight/pull/417, now merged)
  • ✅ ws2811_unittest.cc

❌ Tests running in github action step (currently failing to compile)

Igorshp avatar Dec 12 '20 02:12 Igorshp

unittest.txt

KAJE1977 avatar Dec 13 '20 04:12 KAJE1977

@Igorshp cool!

gretel avatar Dec 13 '20 21:12 gretel

Pretty much all compilation errors resolved.

having trouble with sensor_gyro_unittest.cc, it complains about missing arm_math.h, I belive it could be because i'm compiling it on x86 architecture. Not sure.

Some tests are also failing, expected as the code has diverged since.

Igorshp avatar Dec 16 '20 04:12 Igorshp

@Igorshp the file is at ./lib/main/CMSIS/DSP/Include/arm_math.h but i think it has sth to do with the target supporting SMT or not.

gretel avatar Dec 16 '20 04:12 gretel

@Igorshp the file is at ./lib/main/CMSIS/DSP/Include/arm_math.h but i think it has sth to do with the target supporting SMT or not.

hmm, intresting point. Thanks. I'll check it can be toggled with flags

Igorshp avatar Dec 16 '20 12:12 Igorshp

@Igorshp , PR435_da337b270_unittests.txt

nerdCopter avatar Dec 16 '20 13:12 nerdCopter

Status update

All but one tests compile (sensor_gyro_unittest requires arm_math.h library and I haven't yet figured out how to provide it)

3 tests compile but are failing since code base have moved on.

The github action step fails to run the tests. Looks like environment setup issue.

Igorshp avatar Dec 20 '20 00:12 Igorshp

@Igorshp thanks!

The github action step fails to run the tests. Looks like environment setup issue.

it's a compiler issue - the action will be fine. the current state of the affair is like this:

  • the tests need to be compiled with clang-10 at least
  • ~~or the arm sdk like for the cross compiles but the component we use is not updated yet https://github.com/fiam/arm-none-eabi-gcc/pull/12~~
  • the betaflight folks have worked on this but the discussion is horrifying
  • i'm working on getting your changes and the above merged but not done yet

we should just wait a couple of days for the upstreams to settle. 🍵

gretel avatar Dec 20 '20 03:12 gretel

ok got the test to run to completion. credits to @mikeller 😗

@Igorshp now, i can either PR this up as new or you rebase my branch on your open PR.. i'm fine both ways.

@Quick-Flash the tests show some interesting results including the pid controller 😼

gretel avatar Dec 20 '20 04:12 gretel

@gretel interesting, thanks for the insight!

I've had a fair share of issues with the compiler myself and considering building a docker container to run the tests in. It'll help normalize the testing environment for everyone and from what I understand github actions can use containers. any thoughts?

Then there's matter of broken tests. crsf ones dont look to bad. pid controller stuff though is a bit out of my league at the moment.

Igorshp avatar Dec 20 '20 04:12 Igorshp

I've had a fair share of issues with the compiler myself and considering building a docker container to run the tests in. It'll help normalize the testing environment for everyone and from what I understand github actions can use containers. any thoughts?

no more docker please 🙈 i think it's working fine now.

Then there's matter of broken tests. crsf ones dont look to bad. pid controller stuff though is a bit out of my league at the moment.

there is also the matter of broken implemenations 👯

gretel avatar Dec 20 '20 04:12 gretel

Merged in your changes, let's wait for the build

EDIT: hmm, couple of other commits got pulled in. I'll rebase on master when we're done

Igorshp avatar Dec 20 '20 04:12 Igorshp

i think the Take the trash out out step is also "required" for the test run.

gretel avatar Dec 20 '20 04:12 gretel

raw logs: logs_1229.zip test: Error: Process completed with exit code 2.

nerdCopter avatar Dec 20 '20 23:12 nerdCopter

Tried getting this to work with clang-11 and/or clang-12 for modern OS. easy to change src/test/Makefile, but DWARF/ld errors occur throughout.

[  PASSED  ] 8 tests.
running test_alignsensor_unittest: PASS
linking ../../obj/test/arming_prevention_unittest/arming_prevention_unittest 
/usr/bin/ld: /usr/bin/ld: DWARF error: could not find variable specification at offset 38fb
/usr/bin/ld: DWARF error: could not find variable specification at offset 5979
/usr/bin/ld: DWARF error: could not find variable specification at offset 5a1e
/usr/bin/ld: DWARF error: could not find variable specification at offset 5ac4
/usr/bin/ld: DWARF error: could not find variable specification at offset 5b6f
/usr/bin/ld: DWARF error: could not find variable specification at offset 5c1a
/usr/bin/ld: DWARF error: could not find variable specification at offset 5cc5
/usr/bin/ld: DWARF error: could not find variable specification at offset 5d70
/usr/bin/ld: DWARF error: could not find variable specification at offset 5e1b
../../obj/test/arming_prevention_unittest/arming_prevention_unittest.o:./src/test/../main/flight/servos.h:44: multiple definition of `inputSource_e'; ../../obj/test/arming_prevention_unittest/fc/fc_core.c.o:./src/test/../main/flight/servos.h:44: first defined here
/usr/bin/ld: ../../obj/test/arming_prevention_unittest/arming_prevention_unittest.o:./src/test/unit/arming_prevention_unittest.cc:58: multiple definition of `rcCommand'; ../../obj/test/arming_prevention_unittest/fc/rc_controls.c.o:./src/test/../main/fc/rc_controls.c:73: first defined here
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [Makefile:664: ../../obj/test/arming_prevention_unittest/arming_prevention_unittest] Error 1
make[1]: Leaving directory './src/test'
make: *** [Makefile:540: test] Error 2

if this can be fixed, then master merged in, it will need an #ifdef for SmithPredictor

--- a/src/main/sensors/gyro.h
+++ b/src/main/sensors/gyro.h
@@ -195,7 +195,9 @@ bool gyroOverflowDetected(void);
 bool gyroYawSpinDetected(void);
 uint16_t gyroAbsRateDps(int axis);
 uint8_t gyroReadRegister(uint8_t whichSensor, uint8_t reg);
+#ifdef USE_SMITH_PREDICTOR
 float applySmithPredictor(smithPredictor_t *smithPredictor, float gyroFiltered);
+#endif

nerdCopter avatar May 05 '23 16:05 nerdCopter