Skip to content

Commit

Permalink
Add more tests for edmCheckClassVersion, and fix an a problem with -g…
Browse files Browse the repository at this point in the history
… option
  • Loading branch information
makortel committed Aug 1, 2024
1 parent 62cadd8 commit feaac9f
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion FWCore/Reflection/scripts/edmCheckClassVersion
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ if options.generate and not foundRootDoesNotMatchError and not missingDict:
if normName is not None:
indent = l.find('<')
#this is a class with a problem
classVersion = p.classes[normName][XmlParser.classVersionIndex]
classVersion = p.classes[normName][ClassesDefUtils.XmlParser.classVersionIndex]
code,checksum,rootClassVersion = foundErrors[normName]
hasNoSubElements = (-1 != l.find('/>'))
if code == ClassesDefUtils.errorMustUpdateClassVersion:
Expand Down
1 change: 1 addition & 0 deletions FWCore/Reflection/test/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
</library>

<test name="TestFWCoreReflectionCheckClassVersion" command="run_checkClassVersion.sh"/>
<test name="TestFWCoreReflectionCheckClassVersionUpdate" command="run_checkClassVersionUpdate.sh"/>
<test name="TestFWCoreReflectionDumpClassVersion" command="run_dumpClassVersion.sh"/>
65 changes: 65 additions & 0 deletions FWCore/Reflection/test/run_checkClassVersionUpdate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash -e

SCRAM_TEST_NAME=TestFWCoreReflectionCheckClassVersionUpdate
rm -rf $SCRAM_TEST_NAME
mkdir $SCRAM_TEST_NAME
cd $SCRAM_TEST_NAME

# Create a new CMSSW dev area and build modified DataFormats/TestObjects in it
NEW_CMSSW_BASE=$(/bin/pwd -P)/$CMSSW_VERSION
scram -a $SCRAM_ARCH project $CMSSW_VERSION
pushd $CMSSW_VERSION/src

# Copy FWCore/Reflection code to be able to edit it to make ROOT header parsing to fail
for DIR in ${CMSSW_BASE} ${CMSSW_RELEASE_BASE} ${CMSSW_FULL_RELEASE_BASE} ; do
if [ -d ${DIR}/src/FWCore/Reflection ]; then
mkdir FWCore
cp -Lr ${DIR}/src/FWCore/Reflection FWCore/
break
fi
done
if [ ! -e FWCore/Reflection ]; then
echo "Failed to symlink FWCore/Reflection from local or release area"
exit 1;
fi

# Modify the IntObject class to trigger a new version
#
# Just setting USER_CXXFLAGS for scram is not sufficient,because
# somehow ROOT (as used by edmCheckClassVersion) still picks up the
# version 3 of the class
echo "#define FWCORE_REFLECTION_TEST_INTOBJECT_V4" | cat - FWCore/Reflection/test/stubs/TestObjects.h > TestObjects.h.tmp
mv TestObjects.h.tmp FWCore/Reflection/test/stubs/TestObjects.h


#Set env and build in sub-shel
(eval $(scram run -sh) ; scram build -j $(nproc))

popd

# Prepend NEW_CMSSW_BASE's lib/src paths in to LD_LIBRARY_PATH and ROOT_INCLUDE_PATH
export LD_LIBRARY_PATH=${NEW_CMSSW_BASE}/lib/${SCRAM_ARCH}:${LD_LIBRARY_PATH}
export ROOT_INCLUDE_PATH=${NEW_CMSSW_BASE}/src:${ROOT_INCLUDE_PATH}

# Make the actual test
echo "Initial setup complete, now for the actual test"
XMLPATH=${SCRAM_TEST_PATH}/stubs
LIBFILE=libFWCoreReflectionTestObjects.so

function die { echo Failure $1: status $2 ; exit $2 ; }
function runFailure {
edmCheckClassVersion -l ${LIBFILE} -x ${XMLPATH}/$1 > log.txt && die "edmCheckClassVersion for $1 did not fail" 1
grep -q "$2" log.txt
RET=$?
if [ "$RET" != "0" ]; then
echo "edmCheckClassVersion for $1 did not contain '$2', log is below"
cat log.txt
exit 1
fi
}

runFailure classes_def.xml "error: class 'edmtest::reflection::IntObject' has a different checksum for ClassVersion 3. Increment ClassVersion to 4 and assign it to checksum 2954816125"
runFailure test_def_incorrectVersion.xml "error: for class 'edmtest::reflection::IntObject' ROOT says the ClassVersion is 3 but classes_def.xml says it is 4. Are you sure everything compiled correctly?"

edmCheckClassVersion -l ${LIBFILE} -x ${XMLPATH}/classes_def.xml -g || die "edmCheckClassVersion -g failed" $?
diff -u ${XMLPATH}/test_def_v4.xml classes_def.xml.generated || die "classes_def.xml.generated differs from expectation" $?
9 changes: 9 additions & 0 deletions FWCore/Reflection/test/stubs/TestObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ namespace edmtest::reflection {
IntObject();
IntObject(int v) : value_(v) {}

#ifdef FWCORE_REFLECTION_TEST_INTOBJECT_V4
void set(int v) {
value_ = v;
set_ = true;
}
#endif
int get() const { return value_; }

private:
int value_ = 0;
#ifdef FWCORE_REFLECTION_TEST_INTOBJECT_V4
bool set_ = false;
#endif
};
} // namespace edmtest::reflection

Expand Down
7 changes: 7 additions & 0 deletions FWCore/Reflection/test/stubs/test_def_incorrectVersion.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<lcgdict>
<class name="edmtest::reflection::IntObject" ClassVersion="4">
<version ClassVersion="4" checksum="2954816125"/>
<version ClassVersion="3" checksum="427917710"/>
</class>
<class name="edm::Wrapper<edmtest::reflection::IntObject>"/>
</lcgdict>
7 changes: 7 additions & 0 deletions FWCore/Reflection/test/stubs/test_def_v4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<lcgdict>
<class name="edmtest::reflection::IntObject" ClassVersion="4">
<version ClassVersion="4" checksum="2954816125"/>
<version ClassVersion="3" checksum="427917710"/>
</class>
<class name="edm::Wrapper<edmtest::reflection::IntObject>"/>
</lcgdict>

0 comments on commit feaac9f

Please sign in to comment.