Skip to content

Commit 52635e7

Browse files
committed
add files to test runtime aggregate bounds
1 parent 6817e1b commit 52635e7

File tree

5 files changed

+166
-1
lines changed

5 files changed

+166
-1
lines changed

run_ctest.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,11 @@ if(NOT SKIP_TEST_EXCHANGE_FILE )
133133
SUBMIT_TEST( Test )
134134
endif()
135135

136+
if(NOT SKIP_TEST_CPP_SCHEMA_SPECIFIC )
137+
ctest_test( BUILD "${CTEST_BINARY_DIRECTORY}" APPEND
138+
PARALLEL_LEVEL ${PROCESSOR_COUNT} INCLUDE_LABEL "cpp_schema_specific" )
139+
SUBMIT_TEST( Test )
140+
endif()
141+
142+
136143
# ctest_coverage( )

test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ FILE(GLOB UNITARY_SCHEMAS "${CMAKE_CURRENT_SOURCE_DIR}/unitary_schemas/*.exp")
66
FOREACH(UNITARY_SCHEMA ${UNITARY_SCHEMAS})
77
GET_FILENAME_COMPONENT(SCHEMA_NAME ${UNITARY_SCHEMA} NAME_WE)
88
# setting test_name
9-
SET(TEST_NAME test${SCHEMA_NAME})
9+
SET(TEST_NAME test_unit_${SCHEMA_NAME})
1010
# add test
1111
ADD_TEST(${TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/check-express ${UNITARY_SCHEMA})
1212
set_tests_properties( ${TEST_NAME} PROPERTIES LABELS unitary_schemas )
1313
ENDFOREACH(UNITARY_SCHEMA ${UNITARY_SCHEMAS})
1414

1515
add_subdirectory(p21)
16+
add_subdirectory(cpp)

test/cpp/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2+
3+
#c++ tests
4+
5+
add_subdirectory(schema_specific)
6+
# add_subdirectory(stepcore)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2+
#c++ tests that depend on a particular schema
3+
4+
INCLUDE_DIRECTORIES( ${SCL_SOURCE_DIR}/src/cldai ${SCL_SOURCE_DIR}/src/cleditor ${SCL_SOURCE_DIR}/src/clutils
5+
${SCL_SOURCE_DIR}/src/clstepcore ${SCL_SOURCE_DIR}/src/base )
6+
7+
# ${name} is used for the C++ file name (${name}.cc), and as the suffix for the target and test names
8+
# ${sdai_lib} is the name of the schema lib that is used
9+
# ${args} are additional args for the test executable
10+
FUNCTION( add_schema_dependent_test name sdai_lib args )
11+
add_executable( tst_${name} "${name}.cc" )
12+
set_target_properties( tst_${name} PROPERTIES COMPILE_FLAGS "-I${CMAKE_BINARY_DIR}/${sdai_lib}" )
13+
set_target_properties( tst_${name} PROPERTIES EXCLUDE_FROM_ALL ON )
14+
target_link_libraries( tst_${name} sdai_${sdai_lib} )
15+
add_test( NAME test_${name}
16+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
17+
COMMAND tst_${name} ${args} )
18+
set_tests_properties( test_${name} PROPERTIES DEPENDS build_cpp_sdai_${sdai_lib} LABELS cpp_schema_specific )
19+
ENDFUNCTION( add_schema_dependent_test name sdai_lib args )
20+
21+
BUILD_A_SCHEMA( ${SCL_SOURCE_DIR}/test/unitary_schemas/array_bounds_expr.exp )
22+
add_schema_dependent_test( "aggregate_bound_runtime" "array_bounds_expr"
23+
"${SCL_SOURCE_DIR}/test/p21/test_array_bounds.p21" )
24+
25+
add_test( NAME test_aggregate_bound_runtime_FAIL1
26+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
27+
COMMAND tst_aggregate_bound_runtime "${SCL_SOURCE_DIR}/test/p21/test_array_bounds_FAIL1.p21" )
28+
set_tests_properties( test_aggregate_bound_runtime_FAIL1 PROPERTIES
29+
DEPENDS test_aggregate_bound_runtime WILL_FAIL true LABELS cpp )
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
2+
extern void SchemaInit( class Registry & );
3+
#include "scl_version_string.h"
4+
#include <STEPfile.h>
5+
#include <sdai.h>
6+
#include <STEPattribute.h>
7+
#include <ExpDict.h>
8+
#include <Registry.h>
9+
#include <errordesc.h>
10+
#include <algorithm>
11+
#include <string>
12+
#include <unistd.h>
13+
14+
#include "SdaiTEST_ARRAY_BOUNDS_EXPR.h"
15+
16+
int main( int argc, char * argv[] ) {
17+
18+
if ( argc != 2 ) {
19+
cerr << "Wrong number of args. Use: " << argv[0] << " file.stp" << endl;
20+
exit(1);
21+
}
22+
23+
Registry registry( SchemaInit );
24+
InstMgr instance_list;
25+
STEPfile sfile( registry, instance_list, "", false );
26+
27+
sfile.ReadExchangeFile( argv[1] );
28+
Severity readSev = sfile.Error().severity();
29+
if( readSev != SEVERITY_NULL ) {
30+
sfile.Error().PrintContents(cout);
31+
abort();
32+
}
33+
34+
// Keeps track of the last processed ent id
35+
int search_index = 0;
36+
37+
//find structured_mesh, find the array attribute, and check its bounds as much as possible. need an instance to check 100%.
38+
const EntityDescriptor* ed = registry.FindEntity("Structured_mesh");
39+
AttrDescItr aditr( ed->ExplicitAttr() );
40+
const AttrDescriptor* attrDesc = aditr.NextAttrDesc();
41+
int descAggrCount = 0;
42+
while( attrDesc != 0 ) {
43+
if( ( attrDesc->NonRefType() == ARRAY_TYPE ) && ( attrDesc->AggrElemType() == sdaiINTEGER ) ) {
44+
cout << "Array attribute: " << attrDesc->Name();
45+
const AggrTypeDescriptor* atd = (const AggrTypeDescriptor*) attrDesc->DomainType();
46+
if( !( atd->Bound1Type() == bound_constant ) || !( atd->Bound2Type() == bound_runtime ) ) {
47+
cerr << "Invalid bounds. Exiting." << endl;
48+
abort();
49+
}
50+
cout << " -- bound 1 is a constant (" << atd->Bound1() << "). bound 2 depends upon the instance." << endl;
51+
descAggrCount++;
52+
}
53+
attrDesc = aditr.NextAttrDesc();
54+
}
55+
if( descAggrCount != 1 ) {
56+
cerr << "Expected 1 aggregate attribute descriptor, found " << descAggrCount <<". Exiting." << endl;
57+
abort();
58+
}
59+
60+
61+
// Loop over the instances in the file, check the bound for each
62+
SdaiStructured_mesh* ent;
63+
while ( ENTITY_NULL != (ent = (SdaiStructured_mesh*)
64+
instance_list.GetApplication_instance( "Structured_mesh", search_index ) ) ) {
65+
SDAI_Integer b2;
66+
int instAggrCnt = 0;
67+
IntAggregate* vertex_counts = ent->vertex_counts_();
68+
int cnt = ent->AttributeCount();
69+
STEPattributeList &sal = ent->attributes;
70+
int id = ent->StepFileId();
71+
72+
cout << "Ent #" << id << " - ";
73+
if( cnt != 3 ) {
74+
cerr << "Expected 3 attributes, found " << cnt << ". Exiting." << endl;
75+
abort();
76+
}
77+
if( id > 2 ) {
78+
cerr << "Expected 2 instances, found " << cnt << ". Exiting." << endl;
79+
abort();
80+
}
81+
//loop over the attributes
82+
for( int i = 0; i < cnt; i++ ) {
83+
if( ( sal[i].aDesc->NonRefType() == ARRAY_TYPE ) && ( sal[i].aDesc->AggrElemType() == sdaiINTEGER ) ) {
84+
b2 = ( (AggrTypeDescriptor*) sal[i].aDesc->DomainType() )->Bound2Runtime(ent);
85+
cout << "bound 2: " << b2 << " values: ";
86+
instAggrCnt++;
87+
if( ( ( id == 1 ) && ( b2 != 3 ) ) || ( ( id == 2 ) && ( b2 != 5 ) ) ) {
88+
cerr << "Instance " << id << ": value " << b2 << " is invalid for bound 2.";
89+
cerr << " Expecting 3 for instance #1 or 5 for #2." << endl;
90+
abort();
91+
}
92+
}
93+
}
94+
95+
int node = 0;
96+
int aggrValues[2][5] = {{1,2,3,-1,-1},{9,34,0,3,999999}};
97+
IntNode* aggrNode = (IntNode*) vertex_counts->GetHead();
98+
while( aggrNode != 0 ) {
99+
if( node >= b2 ) {
100+
cerr << "Instance " << id << ": Number of values exceeds upper bound. Exiting." << endl;
101+
abort();
102+
}
103+
cout << aggrNode->value << " ";
104+
if( aggrValues[id-1][node] != aggrNode->value ) {
105+
cerr << "Instance " << id << ": aggregate value " << aggrNode->value << " at index " << node << " is incorrect. Exiting." << endl;
106+
abort();
107+
}
108+
aggrNode = (IntNode*) aggrNode->NextNode();
109+
node++;
110+
}
111+
cout << endl;
112+
113+
if( instAggrCnt != 1 ) {
114+
cerr << "Expected 1 aggregate attribute in this instance, found " << instAggrCnt << ". Exiting." << endl;
115+
abort();
116+
}
117+
118+
119+
MgrNode* mnode = instance_list.FindFileId( id );
120+
search_index = instance_list.GetIndex( mnode ) + 1;
121+
}
122+
}

0 commit comments

Comments
 (0)