Sustainable Software Development in an Academic Setting€¦ · 2 Hartwig Anzt: Sustainable...

Post on 28-Sep-2020

2 views 0 download

Transcript of Sustainable Software Development in an Academic Setting€¦ · 2 Hartwig Anzt: Sustainable...

KIT – The Research University in the Helmholtz Association

Hartwig Anzt, Terry Cojean, Thomas Grűtzmacher, Pratik Nayak, Mike TsaiSteinbuch Centre for Computing (SCC)

www.kit.edu

SustainableSoftwareDevelopmentinanAcademicSetting4thInternationalSymposium onResearchandEducationofComputational Science(RECS)University ofTokyo,October1st,2019

Theseslidesareavailableunder:https://hartwiganzt.github.io/slides/SustainableSoftwareDevelopment.pdf

2 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

What we cover today

• Versioningsystems

• Git workflow

• Git hostingsites

• Continuous Integration(CI)

• GitLab runners

• AutomatedTesting

• UnitTestingwithGoogletest

• SoftwareDocumentationwithDoxygen

Tointeractivelyparticipate inthiscourse,youneedaGitLab account.

• Pleasecreateanaccount(chooseyournamecarefully!)• Pleaselogin• https://gitlab.com/

PratikNayakTerryCojean ThomasGrützmacher

TobiasRibizel

Interactivewebinarwiththehelpof

Forcompleteinteractiveparticipation(onLinuxSystems):

apt-get install git cmake g++ gcovr

MikeTsai

3 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

What is a version control system?

Versioncontrolsystemfortrackingchangesincomputerfiles.

4 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

What is a version control system?

• Distributedversioncontrol

• Coordinatesworkbetweenmultipledevelopers

• Whomadewhatchangesandwhen

• Revertbackatanytime

• Localandremoterepos

Versioncontrolsystemfortrackingchangesincomputerfiles.

ü Keepstrackofcodehistory

ü Takes“snapshots”ofyourfiles

ü Youdecidewhentotakeasnapshot bymakinga”commit”

ü Youcanvisitanysnapshotatanytime

5 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Git Versioning System

Ø git init //Initializelocalgit repository

Ø git add*files //Addfile(s)tosnapshot

Ø git status //Checkchangesnotyetinthesnapshot

Ø git commit*files //Takesnapshot (commitchanges)Ø git commit–m‘putacommentonthiscommit’*files

Git CheatSheet:https://www.git-tower.com/blog/git-cheat-sheet/

6 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Git Versioning System

Ø git init //Initializelocalgit repository

Ø git add*files //Addfile(s)tosnapshot

Ø git status //Checkchangesnotyetinthesnapshot

Ø git commit*files //Takesnapshot (commitchanges)Ø git commit–m‘putacommentonthiscommit’*files

LocalRepository

Git CheatSheet:https://www.git-tower.com/blog/git-cheat-sheet/

7 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Git Versioning System

Ø git init //Initializelocalgit repository

Ø git add*files //Addfile(s)tosnapshot

Ø git status //Checkchangesnotyetinthesnapshot

Ø git commit*files //Takesnapshot (commitchanges)Ø git commit–m‘putacommentonthiscommit’*files

Ø git push //Pushlocalsnapshotstoremoterepo

Ø git pull //Getlatestsnapshot fromremoterepo

Ø git clone*path/to/repo //CloneanexistingremoterepositoryRemoteRepository

LocalRepository

Git CheatSheet:https://www.git-tower.com/blog/git-cheat-sheet/

8 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Git Hosting Sites

• GitHub

• GitLab

• Bitbucket

• … https://en.wikipedia.org/wiki/Comparison_of_source-code-hosting_facilities

WemayjustchooseGitLab forthiscourse• Pleasecreateanaccount(chooseyournamecarefully!)• Pleaselogin• https://gitlab.com/

Theyoffertheenvironmentfortheremoterepository.

9 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Git Hands-On

1. WecreateanAccountatGitLab andlogin.

2. IcreateaprojectonGitLab (\git@gitlab.com:hanzt/recs)

3. Iaddafirstsourcefileandmakeitapublicrepository

4. Youallcloneortheproject:

git clone git@gitlab.com:hanzt/recs

5. Youaddyournametothelocalversionofcontributors.txt

6. Youcheckyourchanges:

git diff

7. Youcommityour localchanges:

git commit –m ‘add my name’ contributors.txt

8. Youpushyourlocalchangestotheremoterepository:

git push origin master

9. Youfix”mergeconflicts”….

10 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Continuous Integration (CI)

clone

• Howdoyoufindoutthecodeisbroken?• Howdowefindoutwhowhichcode

integration introducedthebug?• Howcanwemakesureeverythingworks

atanypointintime?

Sometimes,someoneintroducesabugthatbreaksthecode…

11 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Continuous Integration (CI)

Weneedamechanismthatconstantlychecksthefunctionalityofthemaster“branch”.

clone

ContinuousIntegration

• Howdoyoufindoutthecodeisbroken?• Howdowefindoutwhowhichcode

integration introducedthebug?• Howcanwemakesureeverythingworks

atanypointintime?

Sometimes,someoneintroducesabugthatbreaksthecode…

• Setsupapre-definedenvironment;

• Clonestheremoterepositoryonaserver;

• Triestocompileandrunallpre-definedtests;

• Reportstheoutcome;

12 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Continuous Integration on GitLab

• GitLab supportsGitLab runnersasCIfeature.

• Theycanbeconfiguredviaaddingthefile.gitlab-ci.yml

https://docs.gitlab.com/ee/ci/yaml/

• GitLab runneraresetupviawebinterface.

example.gitlab-ci.yml

LoadimageofOS

UpdateOS

Installpackagesneeded:git cmake g++gcovr

Createdirectory

CallCMake

Buildlibrarygcov checksunittestcoverage

13 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Software TestingAutomatedtesting:Thepracticeofwritingcodetotestthecode,andthenrunthosetestsinanautomatedfashion.

ProductionCode TestCode

14 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Integrationtests:Checktheapplicationsfunctionalitywithitsexternaldependencies.

• Givemoreconfidenceincomplexapplication.• Testsunits/classesaswhole.

End-to-Endtests:Checktheapplicationsfunctionalitywithitsexternaldependenciesanduserinput.

• Testcompleteworkflowandapplicationinteraction.• Veryslowandbrittle.

Software TestingAutomatedtesting:Thepracticeofwritingcodetotestthecode,andthenrunthosetestsinanautomatedfashion.

ProductionCode TestCode

Unittests:Checkthefunctionalityandvalidityofeachbuildingblockwithout itsexternaldependencies.

• Trackdownbugs

Many.Easy-to-write.ExecuteFast.

15 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Integrationtests:Checktheapplicationsfunctionalitywithitsexternaldependencies.

• Givemoreconfidenceincomplexapplication.• Testsunits/classesaswhole.

End-to-Endtests:Checktheapplicationsfunctionalitywithitsexternaldependenciesanduserinput.

• Testcompleteworkflowandapplicationinteraction.• Veryslowandbrittle.

Software TestingAutomatedtesting:Thepracticeofwritingcodetotestthecode,andthenrunthosetestsinanautomatedfashion.

ProductionCode TestCode

Unittests:Checkthefunctionalityandvalidityofeachbuildingblockwithout itsexternaldependencies.

• Trackdownbugs

Many.Easy-to-write.ExecuteFast.

Fewer.Dependencies.

16 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Integrationtests:Checktheapplicationsfunctionalitywithitsexternaldependencies.

• Givemoreconfidenceincomplexapplication.• Testsunits/classesaswhole.

End-to-Endtests:Checktheapplicationsfunctionalitywithitsexternaldependenciesanduserinput.

• Testcompleteworkflowandapplicationinteraction.• Veryslowandbrittle.

Software TestingAutomatedtesting:Thepracticeofwritingcodetotestthecode,andthenrunthosetestsinanautomatedfashion.

ProductionCode TestCode

Unittests:Checkthefunctionalityandvalidityofeachbuildingblockwithout itsexternaldependencies.

• Trackdownbugs

Many.Easy-to-write.ExecuteFast.

Few.Complex.

Fewer.Dependencies.

17 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Unit tests with Googletest

• Frameworktofacilitateunittesting.

• https://github.com/google/googletest

Let’sdoanexample.

Muchofthismaterialistakenfrom NikolaosPothitoshttp://cgi.di.uoa.gr/~pothitos/https://github.com/pothitos/gtest-demo-gitlab

18 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

Software Documentation

• Automatedcodedocumentationtool.

• Convertscommentsinsourcecodeintodocumentation.

• HTML-oriented.

• http://www.doxygen.nl/

• https://github.com/doxygen/doxygen.git

Doxygen is the de facto standard tool for generatingdocumentation from annotated C++ sources, but it alsosupports other popular programming languages such as C,Objective-C, C#, PHP, Java, Python, IDL (Corba, Microsoft, andUNO/OpenOffice flavors), Fortran, VHDL, Tcl, and to someextent D.

Example:https://www.dealii.org/current/doxygen/deal.II/classTorusManifold.html

19 10/01/2019Hartwig Anzt:SustainableSoftwareDevelopmentinanAcademicSetting

References & Further Reading

https://bssw.io/

• https://www.git-tower.com/blog/git-cheat-sheet/• https://github.com/google/googletest• https://github.com/pothitos/gtest-demo-gitlab• https://docs.gitlab.com/ee/ci/yaml/• http://www.doxygen.nl/

Theseslidesareavailableunder:https://hartwiganzt.github.io/slides/SustainableSoftwareDevelopment.pdf