Skip to content

Commit 98ccf70

Browse files
author
Roscoe A. Bartlett
committed
Merge remote-tracking branch 'github/master'
Build/Test Cases Summary Enabled Packages: Enabled all Packages 0) MPI_RELEASE_DEBUG_SHARED => passed: passed=1023,notpassed=0 (69.23 min) Other local commits for this build/test group: 906db00, a542520, bbd234c, 9f3b792, 722aba1, 87ec164, 90dac69
2 parents 9fbdf6e + 906db00 commit 98ccf70

File tree

7 files changed

+738
-254
lines changed

7 files changed

+738
-254
lines changed

common_tools/test/hhmmss_math.py

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
#!/usr/bin/env python
2+
#
3+
# This simple set of python functions makes it easy to do simple math with
4+
# times formatted as <hr>h<min>m<sec>s. This makes it easier to analyze
5+
# timing data that is spit out in that form.
6+
#
7+
8+
import sys
9+
import os
10+
11+
def hms2s(hms):
12+
#print "mmss =", mmss
13+
hms_len = len(hms)
14+
h_idx = hms.find("h")
15+
m_idx = hms.find("m")
16+
s_idx = hms.find("s")
17+
# hours
18+
hours = 0.0
19+
if h_idx > 0:
20+
h_start = 0
21+
hours = float(hms[0:h_idx])
22+
# ToDo: Handle 'm' and 's'
23+
# minutes
24+
minutes = 0.0
25+
if m_idx > 0:
26+
m_start = 0
27+
if h_idx > 0:
28+
m_start = h_idx + 1
29+
minutes = float(hms[m_start:m_idx])
30+
# seconds
31+
seconds = 0.0
32+
if s_idx > 0:
33+
s_start = 0
34+
if m_idx > 0:
35+
s_start = m_idx + 1
36+
elif h_idx > 0:
37+
s_start = h_idx + 1
38+
seconds = float(hms[s_start:s_idx])
39+
return hours*3600 + minutes*60 + seconds
40+
41+
def s2hms(seconds):
42+
s_digits = 5
43+
#print ""
44+
#print "seconds =", seconds
45+
hours = int(seconds) / 3600
46+
#print "hours =", hours
47+
seconds_h_remainder = round(seconds - hours*3600, s_digits)
48+
#print "seconds_h_remainder =", seconds_h_remainder
49+
minutes = int(seconds_h_remainder) / 60
50+
#print "mintues =", minutes
51+
seconds_reminder = round(seconds_h_remainder - minutes*60, s_digits)
52+
#print "seconds_reminder = ", seconds_reminder
53+
h_str = ""
54+
if hours != 0:
55+
h_str = str(hours)+"h"
56+
m_str = ""
57+
if minutes != 0:
58+
m_str = str(minutes)+"m"
59+
s_str = ""
60+
if seconds_reminder != 0.0:
61+
s_str = str(seconds_reminder)+"s"
62+
return h_str + m_str + s_str
63+
64+
def sub_hms(hms1, hms2):
65+
num1 = hms2s(hms1)
66+
num2 = hms2s(hms2)
67+
return s2hms(num1 - num2)
68+
69+
def div_hms(hms_num, hms_denom):
70+
num_num = hms2s(hms_num)
71+
num_denom = hms2s(hms_denom)
72+
return num_num/num_denom
73+
74+
75+
#
76+
# Unit test suite
77+
#
78+
79+
if __name__ == '__main__':
80+
81+
import unittest
82+
83+
class test_hms2s(unittest.TestCase):
84+
85+
def setUp(self):
86+
None
87+
88+
def test_s1(self):
89+
self.assertEqual(hms2s("2s"), 2.0)
90+
91+
def test_s2(self):
92+
self.assertEqual(hms2s("2.53s"), 2.53)
93+
94+
def test_s3(self):
95+
self.assertEqual(hms2s("0m4.5s"), 4.5)
96+
97+
def test_m1(self):
98+
self.assertEqual(hms2s("1m2.4s"), 62.4)
99+
100+
def test_m2(self):
101+
self.assertEqual(hms2s("3m10.531s"), 190.531)
102+
103+
def test_h1(self):
104+
self.assertEqual(hms2s("2h"), 7200.0)
105+
106+
def test_h1(self):
107+
self.assertEqual(hms2s("2.5h"), 9000.0)
108+
109+
def test_h2(self):
110+
self.assertEqual(hms2s("1h2m3s"), 3723.0)
111+
112+
def test_h3(self):
113+
self.assertEqual(hms2s("1h3s"), 3603.0)
114+
115+
class test_s2hms(unittest.TestCase):
116+
117+
def setUp(self):
118+
None
119+
120+
def test_s1(self):
121+
self.assertEqual(s2hms(2.0), "2.0s")
122+
123+
def test_s2(self):
124+
self.assertEqual(s2hms(3.456), "3.456s")
125+
126+
def test_s3(self):
127+
self.assertEqual(s2hms(60.0), "1m")
128+
129+
def test_m1(self):
130+
self.assertEqual(s2hms(75.346), "1m15.346s")
131+
132+
def test_m2(self):
133+
self.assertEqual(s2hms(121.25), "2m1.25s")
134+
135+
def test_m3(self):
136+
self.assertEqual(s2hms(60.0), "1m")
137+
138+
def test_h1(self):
139+
self.assertEqual(s2hms(3600.0), "1h")
140+
141+
def test_h2(self):
142+
self.assertEqual(s2hms(3600.001), "1h0.001s")
143+
144+
def test_h3(self):
145+
self.assertEqual(s2hms(3660.0), "1h1m")
146+
147+
def test_h4(self):
148+
self.assertEqual(s2hms(7140.0), "1h59m")
149+
150+
def test_h5(self):
151+
self.assertEqual(s2hms(7141.0), "1h59m1.0s")
152+
153+
def test_h5(self):
154+
self.assertEqual(s2hms(2*3600+3*60+7.82), "2h3m7.82s")
155+
156+
class test_sub_hms(unittest.TestCase):
157+
158+
def setUp(self):
159+
None
160+
161+
def test_1(self):
162+
self.assertEqual(sub_hms("2s", "1s"), "1.0s")
163+
164+
def test_2(self):
165+
self.assertEqual(sub_hms("1m5.23s", "45s"), "20.23s")
166+
167+
class test_div_hms(unittest.TestCase):
168+
169+
def setUp(self):
170+
None
171+
172+
def test_1(self):
173+
self.assertEqual(div_hms("2s", "1s"), 2.0)
174+
175+
def test_2(self):
176+
self.assertEqual(div_hms("1s", "2s"), 0.5)
177+
178+
def test_3(self):
179+
self.assertEqual(div_hms("1m50s", "55s"), 2.0)
180+
181+
def test_4(self):
182+
self.assertEqual(div_hms("55s", "1m50s"), 0.5)
183+
184+
unittest.main()

common_tools/test/min_sec_math.py

-116
This file was deleted.

test/core/ExamplesUnitTests/CMakeLists.txt

+30-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsHelloWorld
131131
)
132132

133133

134-
135134
TRIBITS_ADD_ADVANCED_TEST( TribitsHelloWorld_ScaleTimeout
136135
OVERALL_WORKING_DIRECTORY TEST_NAME
137136
OVERALL_NUM_MPI_PROCS 1
@@ -181,6 +180,36 @@ TRIBITS_ADD_ADVANCED_TEST( TribitsHelloWorld_ScaleTimeout
181180
)
182181

183182

183+
TRIBITS_ADD_ADVANCED_TEST( TribitsHelloWorld_XSDK_DEFAULTS
184+
OVERALL_WORKING_DIRECTORY TEST_NAME
185+
OVERALL_NUM_MPI_PROCS 1
186+
187+
TEST_0 CMND ${CMAKE_COMMAND}
188+
ARGS
189+
${COMMON_ENV_ARGS_PASSTHROUGH}
190+
-DUSE_XSDK_DEFAULTS=TRUE
191+
-DCMAKE_C_COMPILER=
192+
-DCMAKE_CXX_COMPILER=
193+
-DCMAKE_Fortran_COMPILER=
194+
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsHelloWorld
195+
PASS_REGULAR_EXPRESSION_ALL
196+
"-- XSDK: Setting default BUILD_SHARED_LIBS=TRUE"
197+
"USE_XSDK_DEFAULTS=.TRUE."
198+
"-- XSDK: Setting CMAKE_C_COMPILER from env var CC="
199+
"-- XSDK: Setting CMAKE_CXX_COMPILER from env var CXX="
200+
"-- XSDK: Setting CMAKE_Fortran_COMPILER from env var FC="
201+
"-- XSDK: Setting default CMAKE_BUILD_TYPE=DEBUG"
202+
"-- CMAKE_BUILD_TYPE='DEBUG'"
203+
"-- BUILD_SHARED_LIBS='TRUE'"
204+
"Generating done"
205+
206+
ENVIRONMENT
207+
CC=${CMAKE_C_COMPILER}
208+
CXX=${CMAKE_CXX_COMPILER}
209+
FC=${CMAKE_Fortran_COMPILER}
210+
)
211+
212+
184213
########################################################################
185214
# TribitsExampleProject
186215
########################################################################

tribits/core/package_arch/TribitsAddTestHelpers.cmake

+9
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ ENDFUNCTION()
201201

202202
FUNCTION(TRIBITS_ADD_TEST_PROCESS_HOST_HOSTTYPE ADD_THE_TEST_OUT)
203203

204+
IF ("${${PROJECT_NAME}_HOSTNAME}" STREQUAL "")
205+
SET(${PROJECT_NAME}_HOSTNAME dummy_host)
206+
ENDIF()
207+
204208
SET(ADD_THE_TEST TRUE)
205209

206210
IF (ADD_THE_TEST)
@@ -284,6 +288,11 @@ FUNCTION(TRIBITS_ADD_TEST_PROCESS_CATEGORIES ADD_THE_TEST_OUT)
284288
#PRINT_VAR(${PROJECT_NAME}_TEST_CATEGORIES)
285289
#PRINT_VAR(PARSE_CATEGORIES)
286290

291+
IF ("${${PROJECT_NAME}_TEST_CATEGORIES}" STREQUAL "")
292+
# In case this is not a TriBITS project!
293+
SET(${PROJECT_NAME}_TEST_CATEGORIES BASIC)
294+
ENDIF()
295+
287296
# Process the test categories
288297
ASSERT_DEFINED(${PROJECT_NAME}_TEST_CATEGORIES)
289298
FOREACH(CATEGORY_USR_SET ${${PROJECT_NAME}_TEST_CATEGORIES})

0 commit comments

Comments
 (0)