0

I want to run a regression with a shell script which should start each test via make command. The following is a simple version of my script:

#!/bin/sh                                                                                                                                                                                                                                                                       

testlist="testlist.txt"
while read line;
do
    test_name=$(echo $line | awk '{print $1}')
    program_path=$(echo $line | awk '{print $2}')
    make sim TEST_NAME=$test_name PROGRAM_PATH=$program_path
done < "$testlist"

The problem with the above script is that when make command starts a program, the script goes to the next iteration without waiting for the completion of that program in the previous iteration and continues to read the next line from the file.

Is there any option in make utility to make sure that it waits for the completion of the program? Maybe I'm missing something else.

This is the related part of Makefile:

sim:
    vsim -i -novopt \
    -L $(QUESTA_HOME)/uvm-1.1d \
    -L questa_mvc_lib \
    -do "add wave top/AL_0/*;log -r /*" \
    -G/path=$(PROGRAM_PATH) \
    +UVM_TESTNAME=$(TEST_NAME) +UVM_VERBOSITY=UVM_MEDIUM -sv_seed random
yildizabdullah
  • 1,895
  • 5
  • 24
  • 37
  • 1
    `make` just runs whatever is written in your `Makefile`. If this runs a background process you should check the contents of your `Makefile`. – vdavid Feb 13 '20 at 14:23
  • 1
    Also, you should invoke `#!/bin/bash` instead of `#!/bin/sh` since you are using bash-like syntax using `$()`. And I would recommend giving here-strings to awk instead of piping echos, e.g. `$(awk '{print $1}' <<< $line)`, this is more efficient and less error-prone. – vdavid Feb 13 '20 at 14:26
  • 1
    Use `read -r test_name program_path others; do` for avoiding `awk`. – Walter A Feb 13 '20 at 15:54
  • 1
    Perhaps adding `wait` after `make` will help, but that is a work-around. Can you show your Makefile (update question) ? – Walter A Feb 13 '20 at 15:56
  • @WalterA, I've updated my question as you requested. Could you please take a look at it? – yildizabdullah Feb 13 '20 at 16:27
  • 1
    If you just want to get the first two elements, you don't need `awk` at all. You can just use `while read test_name program_name rest; do ...`. The `read` command takes multiple variable names and will assign each incoming word to the next value, and the last value gets everything left over. – MadScientist Feb 13 '20 at 16:58
  • 1
    As for your question, `make` always waits for all its commands to finish running. I assume you see the `vsim` command being invoked as expected. If it's finishing early it means that the `vsim` command is finishing before the operation is complete; maybe it runs in the background or something. You'll have to check the documentation for that command to see how to either make it run in the foreground, or else add another command to your make recipe that waits for it to finish or something. – MadScientist Feb 13 '20 at 18:04
  • 1
    When you call the `vsim` command from the commandline (without Makefile), and enter `ps -ef` after the command, can you notice something running? Can you change the behaviour by changing the parameters, like removing the `-do`? Does `vsim -help` show something interesting (maybe `-i` is interactiv)? – Walter A Feb 13 '20 at 21:44
  • @WalterA, I looked at the output of `ps -ef` command and noticed that there are a few other processes that are forked by vsim command. That should be the cause of my problem. I'll try to find another way to run the regression. Thanks for your help. – yildizabdullah Feb 14 '20 at 06:54

1 Answers1

1

As OP stated in a comment, he noticed that vsim forks few other processes, that are still running after vsim is finished. So he needs to wait until the other processes are finished.
I emulated your vsim command with a script that forks some sleep processes:

#!/bin/bash
forksome() {
   sleep 3&
   sleep 2&
   sleep 5&
}

echo "Forking some sleep"
forksome

I made a Makefile, that shows your problem after make normal.
When you know which processes are forked, you can make a solution as I demonstrated with make new.

normal: sim
        ps -f

new: sim mywait
        ps -f

sim:
        ./vsim

mywait:
        echo "Waiting for process(es):"
        while pgrep sleep; do sleep 1; done
Walter A
  • 19,067
  • 2
  • 23
  • 43