Search code examples
linuxbashshellgnu-makequestasim

Running a regression with shell script and make utility


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

Solution

  • 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