Skip to content

Commit

Permalink
Add verbose mode to test.py (#42)
Browse files Browse the repository at this point in the history
  - Dump model name when test is started
  - Add verbose flag to test
  • Loading branch information
AnHeuermann committed Feb 4, 2024
1 parent 7b47871 commit 2854981
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Run library test
shell: bash
run: python test.py --branch="${{ matrix.omc-version }}" --noclean configs/sanityCheck.json
run: python test.py --branch="${{ matrix.omc-version }}" --noclean --verbose configs/sanityCheck.json

- name: Generate HTML results
shell: bash
Expand Down
20 changes: 8 additions & 12 deletions README.md
Expand Up @@ -37,19 +37,15 @@ The scripts from this repository can be used to run regression tests for public,
```bash
pip install -r requirements.txt
```
- Install libraries you want to test
- (Optional) Remove already installed libraries
```bash
rm -rf ~/.openmodelica/libraries/
rm -rf /path/to/OpenModelica/build/lib/omlibraries
- OMC will search for libraries in the location provided with test.py argument `--libraries`.
The default value is `/home/username/.openmodelica/libraries/`.
- Install your libraries into the location specified with `--libraries`
or use `loadFile` command inside `loadFileCommands` in the config JSON:
```yml
"loadFileCommands": [
"loadFile(\"/path/to/package.mo\")"
]
```
- Install all available libraries.
```bash
/path/to/omc .CI/installLibraries.mos
```

*or*
- Install your libraries.
- Create configs/myConf.json to specify what libraries to test.
```json
[
Expand Down
15 changes: 12 additions & 3 deletions test.py
Expand Up @@ -92,7 +92,7 @@ def target():
parser.add_argument('--fmi', default=False)
parser.add_argument('--output', default='')
parser.add_argument('--docker', default='')
parser.add_argument('--libraries', default=os.path.expanduser('~/.openmodelica/libraries/'))
parser.add_argument('--libraries', help="Directory omc will search in to load system libraries/libraries to test.", default=os.path.expanduser('~/.openmodelica/libraries/'))
parser.add_argument('--extraflags', default='')
parser.add_argument('--extrasimflags', default='')
parser.add_argument('--ompython_omhome', default='')
Expand All @@ -101,13 +101,15 @@ def target():
parser.add_argument('--ulimitvmem', help="Virtual memory limit (in kB)", type=int, default=8*1024*1024)
parser.add_argument('--default', action='append', help="Add a default value for some configuration key, such as --default=ulimitExe=60. The equals sign is mandatory.", default=[])
parser.add_argument('-j', '--jobs', default=0)
parser.add_argument('-v', '--verbose', action="store_true", help="Verbose mode.", default=False)

args = parser.parse_args()
configs = args.configs
branch = args.branch
result_location = args.output
n_jobs = int(args.jobs)
clean = not args.noclean
verbose = args.verbose
extraflags = args.extraflags
extrasimflags = args.extrasimflags
ompython_omhome = args.ompython_omhome
Expand Down Expand Up @@ -613,14 +615,18 @@ def hashReferenceFiles(s):
print("Created .conf.json files")
sys.stdout.flush()

def runScript(c, timeout, memoryLimit):
def runScript(c, timeout, memoryLimit, verbose):
j = "files/%s.stat.json" % c
try:
os.remove(j)
except:
pass
start=monotonic()
# runCommand("%s %s %s.mos" % (omc_exe, single_thread, c), prefix=c, timeout=timeout)
if verbose:
print("Starting test: %s" % c)
sys.stdout.flush()

if 0 != runCommand("ulimit -v %d; ./testmodel.py --libraries=%s %s --ompython_omhome=%s %s.conf.json > files/%s.cmdout 2>&1" % (memoryLimit, librariespath, ("--docker %s --dockerExtraArgs '%s'" % (docker, " ".join(dockerExtraArgs))) if docker else "", ompython_omhome, c, c), prefix=c, timeout=timeout):
print("files/%s.err" % c)
with open("files/%s.err" % c, "a+") as errfile:
Expand All @@ -646,6 +652,9 @@ def runScript(c, timeout, memoryLimit):
data = {"phase":0}
data["exectime"] = execTime
json.dump(data, open(j,"w"))
if verbose:
print("Finished test: %s - %d[s]" % (c, execTime))
sys.stdout.flush()

def expectedExec(c):
(model,lib,libName,name,data) = c
Expand Down Expand Up @@ -688,7 +697,7 @@ def expectedExec(c):
start_as_time=time.localtime()
testRunStartTimeAsEpoch = int(time.time())
# Need translateModel + make + exe...
cmd_res=Parallel(n_jobs=n_jobs)(delayed(runScript)(name, 2*data["ulimitOmc"]+data["ulimitExe"]+25, data["ulimitMemory"]) for (model,lib,libName,name,data) in tests)
cmd_res=Parallel(n_jobs=n_jobs)(delayed(runScript)(name, 2*data["ulimitOmc"]+data["ulimitExe"]+25, data["ulimitMemory"], verbose) for (model,lib,libName,name,data) in tests)
stop=monotonic()
print("Execution time: %s" % friendlyStr(stop-start))
assert(stop-start >= 0.0)
Expand Down

0 comments on commit 2854981

Please sign in to comment.