Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup (using namespace std) #260

Merged
merged 35 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ef0eaf7
Get rid of using namespace std in tools files
HomesGH May 24, 2023
cb4c493
Get rid of using namespace std in src files
HomesGH May 24, 2023
7d843e4
Add checks for various cases
HomesGH May 24, 2023
c6eac0a
Fix compiling errors regarding std::
HomesGH May 24, 2023
6d52afb
Remove src/MarDyn_version.h as it is generated automatically
HomesGH May 24, 2023
ef56cef
Fixes regarding std::
HomesGH May 24, 2023
86e8ab3
Fix in static code analysis script
HomesGH May 24, 2023
8b43b70
Fix in static code analysis script
HomesGH May 24, 2023
f147e77
Merge branch 'codeCleanup' of https://github.com/ls1mardyn/ls1-mardyn…
HomesGH May 24, 2023
c879bf8
Fix of std:: in python files
HomesGH May 25, 2023
e6cd790
remove and use Log::global_log everywhere
FG-TUM May 26, 2023
35ee376
Add CI check for static code analysis
HomesGH May 26, 2023
5fd975d
Fix in CI
HomesGH May 26, 2023
eb58e92
Fix in CI (indent)
HomesGH May 26, 2023
c6b7edc
Fix in CI (print)
HomesGH May 26, 2023
0968d1f
CI Static code analysis: make checkout master work
HomesGH May 26, 2023
b06a0c6
CI Static code analysis: cleanup
HomesGH May 26, 2023
3fcea1b
CI job summary - use Markdown
HomesGH May 26, 2023
0d6f851
CI - further cleanup
HomesGH May 26, 2023
217cc56
CI - final cleanup
HomesGH May 26, 2023
12cb3c4
Update static code analysis script
HomesGH Jun 9, 2023
544be4e
Smaller formatting and fix some warnings to trigger CI
HomesGH Jun 12, 2023
148ab42
Fix in static code analysis script
HomesGH Jun 12, 2023
7cca072
Add newline if missing
HomesGH Jun 12, 2023
c416d09
Replace CRLF line endings
HomesGH Jun 12, 2023
7577212
Merge branch 'master' into codeCleanup
FG-TUM Jun 12, 2023
5db9788
add missing namespace prefix
FG-TUM Jun 12, 2023
bca7c93
more missing namespaces
FG-TUM Jun 12, 2023
e8835b4
add missing line endings and convert CRLFs
FG-TUM Jun 12, 2023
720a367
purge all trailing whitespaces
FG-TUM Jun 12, 2023
ed1c7ea
chop some long lines
FG-TUM Jun 12, 2023
4ac864f
fix include order
FG-TUM Jun 12, 2023
28dfeba
remove one redundant empty line
FG-TUM Jun 12, 2023
2b41ba2
Merge branch 'master' into codeCleanup
HomesGH Oct 10, 2023
89e9198
Remove pre-tests with cpplint
HomesGH Oct 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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