Skip to content

Commit

Permalink
Add basic test for simpleElementExample checkpointing
Browse files Browse the repository at this point in the history
  • Loading branch information
bliu1013 committed Oct 3, 2024
1 parent 6f707e3 commit 15f3b40
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 27 deletions.
41 changes: 41 additions & 0 deletions src/sst/elements/simpleElementExample/tests/basicCheckpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sst

# Test a basic param
basicParam = sst.Component("basicParam", "simpleElementExample.basicParams")
params = {
"int_param" : 20,
"bool_param" : "false",
"uint32_param" : "678",
"array_param" : "[0, 1, 5, 20, -1 ]",
"example_param" : "a:92",
}
basicParam.addParams(params)

# Run example 0
component0 = sst.Component("c0", "simpleElementExample.example0")
component1 = sst.Component("c1", "simpleElementExample.example0")

params = {
"eventsToSend" : 50, # Required parameter, error if not provided
"eventSize" : 32 # Optional parameter, defaults to 16 if not provided
}
component0.addParams(params)
component1.addParams(params)

link = sst.Link("component_link0")
link.connect( (component0, "port", "1ns"), (component1, "port", "1ns") )

# Run example 1
component2 = sst.Component("c2", "simpleElementExample.example1")
component3 = sst.Component("c3", "simpleElementExample.example1")

component2.addParams(params)
component3.addParams(params)

link = sst.Link("component_link1")
link.connect( (component2, "port", "1ns"), (component3, "port", "1ns") )

sst.setStatisticLoadLevel(7)
sst.setStatisticOutput("sst.statOutputConsole")
sst.enableAllStatisticsForComponentType("simpleElementExample.example0")
sst.enableAllStatisticsForComponentType("simpleElementExample.example1")
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ def test_basic_simlifecycle(self):
def test_basic_subcomponent(self):
self.simple_components_template("basicSubComponent")

def test_basic_checkpoint(self):
self.simple_components_template("basicCheckpoint", checkpoint=True)

#def test_simple_rng_component_marsaglia(self):
# self.simple_components_template("simpleRNGComponent_marsaglia", striptotail=1)

#####

def simple_components_template(self, testcase, striptotail=0):
def simple_components_template(self, testcase, striptotail=0, checkpoint=False):
# Get the path to the test files
test_path = self.get_testsuite_dir()
outdir = self.get_test_output_run_dir()
Expand All @@ -75,29 +78,51 @@ def simple_components_template(self, testcase, striptotail=0):
errfile = "{0}/{1}.err".format(outdir, testDataFileName)
mpioutfiles = "{0}/{1}.testfile".format(outdir, testDataFileName)

self.run_sst(sdlfile, outfile, errfile, mpi_out_files=mpioutfiles)

testing_remove_component_warning_from_file(outfile)

# Copy the outfile to the cmpfile
os.system("cp {0} {1}".format(outfile, cmpfile))

if striptotail == 1:
# Post processing of the output data to scrub it into a format to compare
os.system("grep Random {0} > {1}".format(outfile, tmpfile))
os.system("tail -5 {0} > {1}".format(tmpfile, cmpfile))

# NOTE: THE PASS / FAIL EVALUATIONS ARE PORTED FROM THE SQE BAMBOO
# BASED testSuite_XXX.sh THESE SHOULD BE RE-EVALUATED BY THE
# DEVELOPER AGAINST THE LATEST VERSION OF SST TO SEE IF THE
# TESTS & RESULT FILES ARE STILL VALID

# Perform the tests
if os_test_file(errfile, "-s"):
log_testing_note("simpleComponents test {0} has a Non-Empty Error File {1}".format(testDataFileName, errfile))

cmp_result = testing_compare_sorted_diff(testcase, cmpfile, reffile)
if (cmp_result == False):
diffdata = testing_get_diff_data(testcase)
log_failure(diffdata)
self.assertTrue(cmp_result, "Sorted Output file {0} does not match sorted Reference File {1}".format(cmpfile, reffile))
if not checkpoint:
self.run_sst(sdlfile, outfile, errfile, mpi_out_files=mpioutfiles)

testing_remove_component_warning_from_file(outfile)

# Copy the outfile to the cmpfile
os.system("cp {0} {1}".format(outfile, cmpfile))

if striptotail == 1:
# Post processing of the output data to scrub it into a format to compare
os.system("grep Random {0} > {1}".format(outfile, tmpfile))
os.system("tail -5 {0} > {1}".format(tmpfile, cmpfile))

# NOTE: THE PASS / FAIL EVALUATIONS ARE PORTED FROM THE SQE BAMBOO
# BASED testSuite_XXX.sh THESE SHOULD BE RE-EVALUATED BY THE
# DEVELOPER AGAINST THE LATEST VERSION OF SST TO SEE IF THE
# TESTS & RESULT FILES ARE STILL VALID

# Perform the tests
if os_test_file(errfile, "-s"):
log_testing_note("simpleComponents test {0} has a Non-Empty Error File {1}".format(testDataFileName, errfile))

cmp_result = testing_compare_sorted_diff(testcase, cmpfile, reffile)
if (cmp_result == False):
diffdata = testing_get_diff_data(testcase)
log_failure(diffdata)
self.assertTrue(cmp_result, "Sorted Output file {0} does not match sorted Reference File {1}".format(cmpfile, reffile))

# Checkpoint test
else:
cptfreq = "15us"
cptrestart = "0_15000000"

# Generate checkpoint
sdlfile_generate = "{0}/{1}.py".format(test_path,testcase)
outfile_generate = "{0}/{1}_generate.out".format(outdir,testcase)
options_checkpoint="--checkpoint-sim-period={0} --checkpoint-prefix={1}".format(cptfreq,testcase)
self.run_sst(sdlfile_generate, outfile_generate, other_args=options_checkpoint)

# Run from restart
sdlfile_restart = "{0}/{1}/{1}_{2}/{1}_{2}.sstcpt".format(outdir,testcase,cptrestart)
outfile_restart = "{0}/{1}_restart.out".format(outdir, testcase)
options_restart = "--load-checkpoint"
self.run_sst(sdlfile_restart, outfile_restart, other_args=options_restart)

# Check that restart output is a subset of checkpoint output
cmp_result = testing_compare_filtered_subset(outfile_restart, outfile_generate)
self.assertTrue(cmp_result, "Output/Compare file {0} does not match Reference File {1}".format(outfile_restart, outfile_generate))

0 comments on commit 15f3b40

Please sign in to comment.