Skip to content

Commit

Permalink
Merge pull request ls1mardyn#260 from ls1mardyn/codeCleanup
Browse files Browse the repository at this point in the history
Code cleanup (using namespace std)
  • Loading branch information
FG-TUM authored Oct 16, 2023
2 parents baca393 + 89e9198 commit f3a8ba4
Show file tree
Hide file tree
Showing 550 changed files with 8,176 additions and 8,183 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ls1_staticCodeAnalysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Static-Code-Analysis

on:
push:
# pushes to master
branches: [ master ]
pull_request:
# PRs to master
branches: [ master ]

jobs:
static_analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup
run: |
sudo apt-get update
sudo apt-get install -y cpplint
- name: Run static code analysis script
run: ./checks/run-staticAnalysis.sh $PWD
52 changes: 52 additions & 0 deletions checks/check-buildOptions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
# Script to test the building process by altering through different build options
# It uses the default settings and sets the specified options one by one

numJobs=20

checkFolder=$PWD
buildFolder=$PWD/../build_test_$(date '+%Y-%m-%d')

declare -A optionsList

optionsList[ENABLE_MPI]=ON
optionsList[VECTOR_INSTRUCTIONS]=SSE
optionsList[VECTOR_INSTRUCTIONS]=AVX2
optionsList[CMAKE_BUILD_TYPE]=Debug
optionsList[OPENMP]=ON
optionsList[ENABLE_AUTOPAS]=ON
optionsList[ENABLE_UNIT_TESTS]=ON
optionsList[QUICKSCHED]=ON
optionsList[FMM_FFT]=ON
optionsList[WITH_PAPI]=ON
optionsList[ENABLE_ALLLBL]=ON
optionsList[ENABLE_VTK]=ON
optionsList[REDUCED_MEMORY_MODE]=ON


# CMAKE
mkdir -p $buildFolder
cd $buildFolder

echo "Running CMAKE in folder: $buildFolder"

for option in "${!optionsList[@]}"
do
echo " Running option: ${option}=${optionsList[${option}]}"
rm $buildFolder/* -rf
( CC=mpicc CXX=mpicxx cmake -D${option}=${optionsList[${option}]} .. && make -j${numJobs} ; echo "$?" ) &> $checkFolder/build_test_cmake_${option}.log
done


# MAKE
cd $checkFolder/../src

echo "Running make in src"

for option in "${!optionsList[@]}"
do
echo " Running option: ${option}=${optionsList[${option}]}"
make clean &> /dev/null
( make -j${numJobs} -f Makefile ${option}=${optionsList[${option}]} ; echo "$?" ) &> $checkFolder/build_test_make_${option}.log
done

82 changes: 82 additions & 0 deletions checks/run-staticAnalysis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
# Script to run static code analysis

#set strict pipefail option
#set -eo pipefail

# A path to the root folder of ls1 mardyn can be set via an argument; if not, the parent folder of "checks" is used
if [ $# -eq 1 ]
then
rootFolder=$1
else
rootFolder=$PWD/..
fi

echo "Running in $rootFolder"

warnings=""

codeFiles=$( find $rootFolder/src -name "*.h" -or -name "*.cpp" -printf "%p " )

# Similar to check_format of MegaMol repo
for file in $codeFiles; do

# Check if using namespace std is used
if grep -q "using namespace std;" "$file"; then
echo "\"using namespace std;\" was used in $file"
warnings+="Do not use \"using namespace std;\"\n"
fi

# Check if using Log::global_log is used
if grep -q "using Log::global_log;" "$file"; then
echo "\"using Log::global_log;\" was used in $file"
warnings+="Do not use \"using Log::global_log;\"\n"
fi

# Check if file is UTF-8 (or ASCII)
encoding=$(file -b --mime-encoding "$file")
if [[ $encoding != "us-ascii" && $encoding != "utf-8" ]]; then
echo "The following file is not ASCII/UTF-8 encoded: $file ($encoding)"
echo " Fix with:"
echo " tmp_file=\$(mktemp)"
echo " iconv -f \"\$(file -b --mime-encoding \"$file\")\" -t utf-8 -o \"\$tmp_file\" \"\$file\""
echo " mv -f \"\$tmp_file\" \"\$file\""
warnings+="At least one file is not ASCII/UTF-8 encoded\n"
fi

# Check if file contains CRLF line endings
fileinfo=$(file -k "$file")
if [[ $fileinfo == *"CRLF"* ]]; then
echo "The following file contains CRLF line endings: $file"
echo " Fix with:"
echo " sed -i 's/\r$//' \"$file\""
sed -i 's/\r$//' "$file"
warnings+="At least one file contains CRLF line endings\n"
fi

# Check if file starts with BOM
if [[ $fileinfo == *"BOM"* ]]; then
echo "The following file starts with BOM: $file"
echo " Fix with:"
echo " sed -i '1s/^\xEF\xBB\xBF//' \"$file\""
warnings+="At least one file starts with BOM\n"
fi

# Check if file ends with newline
if [[ -n "$(tail -c 1 "$file")" ]]; then
echo "The following file does not end with newline: $file"
echo " Fix with:"
echo " sed -i -e '\$a\' \"$file\""
warnings+="At least one file does not end with newline\n"
fi

done

printf "\n\n\n" # Some space to make output clearer

# Only print warnings once to job summary
warnings=$(printf "$warnings" | sort | uniq)
warnings="# Warnings\n"$warnings"\n\n"

printf "\n$warnings\n" # Print to job output
printf "\n$warnings\n" >> $GITHUB_STEP_SUMMARY # Print to job summary
31 changes: 31 additions & 0 deletions checks/run-validation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Testscript running validation tests according to GitHub Actions but without comparison to master
#
# Copyright (c) 2023 Simon Homes
#

repoPath="$PWD/.." # Path to root directory

export OMP_NUM_THREADS=2

logfileName="${repoPath}/examples/run-validation.log"
rm -f ${logfileName}

IFS=$'\n'
for i in $(cat "${repoPath}/examples/example-list.txt" )
do
# skip if comment or empty line
if [[ $i == \#* || -z "$i" ]]
then
continue
fi
cd ${repoPath}/examples/$(dirname $i)

# run the examples
printf "Running example: ${i} ... " | tee -a ${logfileName}
EXE=${repoPath}/build/src/MarDyn

mpirun --oversubscribe -np 4 ${EXE} $(basename $i) --steps=20 | tee -a ${logfileName}
printf "done\n"
done

Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ BaseTestCase::~BaseTestCase()
}


void
void
BaseTestCase::setUp()
{
}


void
void
BaseTestCase::tearDown()
{
}


void
void
BaseTestCase::testUsingCheckIt()
{
checkIt();
}


void
void
BaseTestCase::checkIt()
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ ExceptionTest::~ExceptionTest()
}


void
void
ExceptionTest::setUp()
{
}


void
void
ExceptionTest::tearDown()
{
}


void
void
ExceptionTest::testConstructor()
{
const CPPUNIT_NS::Message message( "a message" );
const CPPUNIT_NS::SourceLine sourceLine( "dir/afile.cpp", 17 );

CPPUNIT_NS::Exception e( message, sourceLine );

CPPUNIT_ASSERT_EQUAL( message.shortDescription(), e.message().shortDescription() );
CPPUNIT_ASSERT( sourceLine == e.sourceLine() );
}


void
void
ExceptionTest::testDefaultConstructor()
{
CPPUNIT_NS::Exception e;
Expand All @@ -53,7 +53,7 @@ ExceptionTest::testDefaultConstructor()
}


void
void
ExceptionTest::testCopyConstructor()
{
CPPUNIT_NS::SourceLine sourceLine( "fileName.cpp", 123 );
Expand All @@ -63,7 +63,7 @@ ExceptionTest::testCopyConstructor()
}


void
void
ExceptionTest::testAssignment()
{
CPPUNIT_NS::SourceLine sourceLine( "fileName.cpp", 123 );
Expand All @@ -74,7 +74,7 @@ ExceptionTest::testAssignment()
}


void
void
ExceptionTest::testClone()
{
CPPUNIT_NS::SourceLine sourceLine( "fileName.cpp", 123 );
Expand All @@ -84,8 +84,8 @@ ExceptionTest::testClone()
}


void
ExceptionTest::checkIsSame( CPPUNIT_NS::Exception &e,
void
ExceptionTest::checkIsSame( CPPUNIT_NS::Exception &e,
CPPUNIT_NS::Exception &other )
{
std::string eWhat( e.what() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ExceptionTest : public CPPUNIT_NS::TestFixture
private:
ExceptionTest( const ExceptionTest &copy );
void operator =( const ExceptionTest &copy );
void checkIsSame( CPPUNIT_NS::Exception &e,
void checkIsSame( CPPUNIT_NS::Exception &e,
CPPUNIT_NS::Exception &other );

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ExceptionTestCaseDecoratorTest::~ExceptionTestCaseDecoratorTest()
}


void
void
ExceptionTestCaseDecoratorTest::setUp()
{
m_testListener = new MockTestListener( "mock-testlistener" );
Expand All @@ -33,7 +33,7 @@ ExceptionTestCaseDecoratorTest::setUp()
}


void
void
ExceptionTestCaseDecoratorTest::tearDown()
{
delete m_decorator;
Expand All @@ -42,7 +42,7 @@ ExceptionTestCaseDecoratorTest::tearDown()
}


void
void
ExceptionTestCaseDecoratorTest::testNoExceptionThrownFailed()
{
m_testListener->setExpectedAddFailureCall(1);
Expand All @@ -56,7 +56,7 @@ ExceptionTestCaseDecoratorTest::testNoExceptionThrownFailed()
}


void
void
ExceptionTestCaseDecoratorTest::testExceptionThrownPass()
{
m_testListener->setExpectNoFailure();
Expand Down
Loading

0 comments on commit f3a8ba4

Please sign in to comment.