command_hooks and :pre_test:

428 views
Skip to first unread message

Łukasz Przeniosło

unread,
Mar 11, 2021, 8:56:02 AM3/11/21
to ThrowTheSwitch Forums
Hi,
I am following this example to run a command before the test starts. I tried the following example but replaced "post" with "pre":

:tools: 
  :pre_test: 
     - :executable: echo 
       :arguments: "${1} was glorious!" 
     - :executable: echo :arguments: 
       - it kinda made me cry a little. 
       - you?

But the test the doesn't "compile":

Traceback (most recent call last):
9: from /usr/local/bin/ceedling:23:in `<main>'
8: from /usr/local/bin/ceedling:23:in `load'
7: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/bin/ceedling:329:in `<top (required)>'
6: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling.rb:66:in `load_project'
5: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling.rb:66:in `load'
4: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling/rakefile.rb:47:in `<top (required)>'
3: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling/setupinator.rb:29:in `do_setup'
2: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling/configurator.rb:132:in `tools_setup'
1: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling/configurator.rb:132:in `each_key'
/var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling/configurator.rb:136:in `block in tools_setup': no implicit conversion of Symbol into Integer (TypeError)

From a different thread in this forums I was suggested a different syntax, like this:

  :pre_test:
    :executable: echo
    :arguments:
      - "test123"

It runs, and I see "Running Hook pre_test..." when running ceedling, but there is no echo output. I have created a script called link_gen.sh in the project folder and added the following to the project file:

  :pre_test:
    :executable: link_gen.sh

But then it does not work as Ceedling seems to not see the script:

/var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling/system_wrapper.rb:25: warning: Insecure world writable dir /opt/microchip/xc16/v1.41/bin in PATH, mode 040777
ERROR: Config filepath [:tools][:pre_test][:executable]['link_gen.sh'] does not exist in system search paths.
Traceback (most recent call last):
7: from /usr/local/bin/ceedling:23:in `<main>'
6: from /usr/local/bin/ceedling:23:in `load'
5: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/bin/ceedling:329:in `<top (required)>'
4: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling.rb:66:in `load_project'
3: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling.rb:66:in `load'
2: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling/rakefile.rb:47:in `<top (required)>'
1: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling/setupinator.rb:32:in `do_setup'
/var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling/configurator.rb:304:in `validate': unhandled exception

If I were to add the directory to the project file so Ceedling can see it- how to do that? I would appreciate all help.


Mark Vander Voord

unread,
Mar 11, 2021, 9:07:15 AM3/11/21
to ThrowTheSwitch Forums
Search the documentation https://github.com/ThrowTheSwitch/Ceedling/blob/master/docs/CeedlingPacket.md for "Special case: PATH handling" and you'll find what you're looking for.

Mark

--
You received this message because you are subscribed to the Google Groups "ThrowTheSwitch Forums" group.
To unsubscribe from this group and stop receiving emails from it, send an email to throwtheswitc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/throwtheswitch/42bb652d-181d-4977-a2fb-d4b1ca185407n%40googlegroups.com.

Łukasz Przeniosło

unread,
Mar 11, 2021, 9:45:42 AM3/11/21
to ThrowTheSwitch Forums
Hi Mark,
My :environment: section is currently empty.

...
:environment:

:extension:
  :executable: .out
...

I now add the path entry:

...
:release_build:
 :output: MyPicApp.out
 :use_assembly: FALSE

:environment:
  - :path:
    - scripts

:extension:
  :executable: .out
...

But now it is not possible to build the project anymore:

ERROR: Config filepath [:tools][:release_compiler][:executable]['xc16-gcc'] does not exist in system search paths.
ERROR: Config filepath [:tools][:release_linker][:executable]['xc16-gcc'] does not exist in system search paths.
ERROR: Config filepath [:tools][:test_compiler][:executable]['xc16-gcc'] does not exist in system search paths.
ERROR: Config filepath [:tools][:test_file_preprocessor][:executable]['gcc'] does not exist in system search paths.
ERROR: Config filepath [:tools][:test_file_preprocessor_directives][:executable]['gcc'] does not exist in system search paths.
ERROR: Config filepath [:tools][:test_fixture][:executable]['ruby'] does not exist in system search paths.
ERROR: Config filepath [:tools][:test_includes_preprocessor][:executable]['gcc'] does not exist in system search paths.
ERROR: Config filepath [:tools][:test_linker][:executable]['xc16-gcc'] does not exist in system search paths.
Traceback (most recent call last):
7: from /usr/local/bin/ceedling:23:in `<main>'
6: from /usr/local/bin/ceedling:23:in `load'
5: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/bin/ceedling:329:in `<top (required)>'
4: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling.rb:66:in `load_project'
3: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling.rb:66:in `load'
2: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling/rakefile.rb:47:in `<top (required)>'
1: from /var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling/setupinator.rb:32:in `do_setup'
/var/lib/gems/2.5.0/gems/ceedling-0.31.0/lib/ceedling/configurator.rb:304:in `validate': unhandled exception

What I also tried is this:

...
:paths:
  :test:
    - +:test/**
    - -:test/support
  :source:
    - src/**
  :support:
    - test/support
  :include:
    - "/opt/microchip/xc16/v1.41/support/dsPIC33E/h/"
  :system:
    - scripts
...

The build runs, but my script.sh inside the scripts dir is still unreachable.

I would appreciate your further feedback. 


Mark Vander Voord

unread,
Mar 11, 2021, 9:48:31 AM3/11/21
to ThrowTheSwitch Forums
Instead of adding to the existing path, you replaced the path with ONLY your new path. At the link I sent, there is a line that pulls the current path back in as one of the lines. you're going to need that line to find your compiler, etc. :)

Mark

Łukasz Przeniosło

unread,
Mar 11, 2021, 10:19:36 AM3/11/21
to ThrowTheSwitch Forums
You are right Mark, thank you! Now In the build I see: "Running Hook pre_test...". The problem is I am sure my script is not being run, as I see no output from it. I assumed maybe stdout is somewhat blocked so I added a file writing line:

#! /bin/bash

echo 'Hello, World!'
echo 'a' > tmp.txt

But after running the build the file tmp.txt is not in the directory... Also it seems that Ceedling sees the scripts/script.sh file, because of I change its name in the project file it complains that it does not exist. Is it possible I am still missing something...?

Łukasz Przeniosło

unread,
Mar 11, 2021, 10:40:32 AM3/11/21
to ThrowTheSwitch Forums
I attach both the script and the project file for clarity. The link_gen.sh is placed in the scripts dir in the project structure.

--
Pozdrawiam / Best Regards,
Łukasz Przeniosło



You received this message because you are subscribed to a topic in the Google Groups "ThrowTheSwitch Forums" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/throwtheswitch/wTinNvX8c10/unsubscribe.
To unsubscribe from this group and all its topics, send an email to throwtheswitc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/throwtheswitch/a0a5dcff-be59-454b-8ce0-98552e407f36n%40googlegroups.com.
link_gen.sh
project.yml

Mark Vander Voord

unread,
Mar 11, 2021, 11:51:45 AM3/11/21
to ThrowTheSwitch Forums
Unless you're running with full verbosity, you're not going to see anything returned from your script from the command line. 

More concerning is that the file isn't getting created. I would expect it to show up given what you have here. 

I'm not in a position to look into the details at the moment, but one thing that might be worth trying is to specify the arguments as empty for this new tool:

:arguments: [ ]

Łukasz Przeniosło

unread,
Mar 11, 2021, 11:57:46 AM3/11/21
to ThrowTheSwitch Forums
Mark,
I have updated the script with empty arguments as suggested: https://pastebin.com/qRqJMm4R
Unfortunately the file is still not created. Is it possible the working dir for the echo is different than the one from within the script is run (I am reaching here...)?
How can I increase the verbosity level of Ceedling? Maybe that would help.

Thank you, Lukasz

Mark Vander Voord

unread,
Mar 11, 2021, 12:33:25 PM3/11/21
to ThrowTheSwitch Forums
If you're running `ceedling test:all` you can insert a boost to verbosity like `ceedling verbosity[4] test:all`

I believe the script should be executed from the same directory as you are calling ceedling (where the project.yml file is)

Łukasz Przeniosło

unread,
Mar 11, 2021, 3:54:02 PM3/11/21
to ThrowTheSwitch Forums
Double hit!

If you're running `ceedling test:all` you can insert a boost to verbosity like `ceedling verbosity[4] test:all`

So now when I run the command with increased verbosity level, one can see that:

(eval):1: warning: Insecure world writable dir /opt/microchip/xc16/v1.41/bin in PATH, mode 040777

Test 'test_cqm.c'
-----------------
Running Hook pre_test...
> Shell executed command:
'link_gen.sh'
> Produced output:
Hello, World!

> Shell executed command:
'gcc -E -MM -MG -I"/var/lib/gems/2.5.0/gems/ceedling-0.31.0/vendor/unity/src" -I"/var/lib/gems/2.5.0/gems/ceedling-0.31.0/vendor/cmock/src" -I"build/test/mocks" -I"test" -I"test/simulation" -I"test/support" -I"src" -I"/opt/microchip/xc16/v1.41/support/dsPIC33E/h" -D__dsPIC33EP512MU810__ -DUNITY_INT_WIDTH=16 -DCMOCK_MEM_INDEX_TYPE=uint16_t -DCMOCK_MEM_PTR_AS_INT=uint16_t -DCMOCK_MEM_ALIGN=1 -DCMOCK_MEM_SIZE=4096 -DTEST -D__dsPIC33EP512MU810__ -DUNITY_INT_WIDTH=16 -DCMOCK_MEM_INDEX_TYPE=uint16_t -DCMOCK_MEM_PTR_AS_INT=uint16_t -DCMOCK_MEM_ALIGN=1 -DCMOCK_MEM_SIZE=4096 -DTEST -DGNU_COMPILER "build/temp/_test_cqm.c"'
...

So my script is indeed being ran.

I believe the script should be executed from the same directory as you are calling ceedling (where the project.yml file is)

So in fact the file is not being created in the scripts dir, in which the link_gen.sh is located, but in the project dir as specified by you:

#: ls -l
total 9
drwxrwx--- 1 root vboxsf    0 mar 10 17:19 build
-rwxrwx--- 1 root vboxsf    6 mar 10 13:08 gitignore
-rwxrwx--- 1 root vboxsf 3289 mar 11 17:53 project.yml
-rwxrwx--- 1 root vboxsf  755 sty 12 04:43 README.md
drwxrwx--- 1 root vboxsf    0 mar 11 17:54 scripts
drwxrwx--- 1 root vboxsf    0 mar 10 13:58 src
drwxrwx--- 1 root vboxsf    0 mar 10 13:13 test
drwxrwx--- 1 root vboxsf    0 mar 10 22:35 tmp_cqm
-rwxrwx--- 1 root vboxsf    2 mar 11 21:47 tmp.txt

So changing the "echo 'a' > tmp.txt" to "echo 'a' > scripts/tmp.txt" yields the expected by my result.

Again, thank you very much for your great support Mark!

Reply all
Reply to author
Forward
0 new messages