Contents


p1-stats

Style Checking

This tutorial will show you how to run style checking tools on your source code.

Table of Contents

Style criteria

We will use three tools to check the style of your code.

cppcheck performs compile-time checks for errors that can cause undefined behavior.

oclint checks

cpd checks for significant code duplication.

Note: We prohibit the phrase oclint, regardless of capitalization, from appearing in your source files, as it can be used to turn off oclint checks.

Prerequisites

We’re assuming that you already have a folder with starter source code in it, e.g., p1-stats/.

$ pwd
/Users/awdeorio/src/eecs280/p1-stats
$ ls
Makefile      main_test.out.correct  p1_library.h  stats_public_test.cpp
main.cpp      main_test_data.tsv     stats.cpp     stats_tests.cpp
main_test.in  p1_library.cpp         stats.h

You can connect to CAEN Linux. See the CAEN Linux tutorial for help.

$ ssh awdeorio@login.engin.umich.edu
The authenticity of host 'login.engin.umich.edu (141.213.74.65)' can't be established.
ECDSA key fingerprint is SHA256:LL0GPTtaVGa6gvv2kVpGq4ZULA1l5pw2wXC4dK3ymIk.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'login.engin.umich.edu,141.213.74.65' (ECDSA) to the list of known hosts.
Password: 
Duo two-factor login for awdeorio

Enter a passcode or select one of the following options:

 1. Duo Push to XXX-XXX-2735
 2. Phone call to XXX-XXX-2735
 3. SMS passcodes to XXX-XXX-2735

Passcode or option (1-3): 1
Success. Logging you in...
...
-bash-4.2$ exit
Connection to login.engin.umich.edu closed.

Copy code to CAEN Linux

We’re going to synchronize our code to CAEN Linux many times. These shortcuts will let you synchronize quickly and easily.

Be sure that you can avoid repeated two-factor authentication (2FA). In a separate terminal, connect to CAEN Linux with SSH so you won’t have to enter your password again.

$ ssh awdeorio@login.engin.umich.edu
Password:
Duo two-factor login for awdeorio

Enter a passcode or select one of the following options:

 1. Duo Push to XXX-XXX-2735
 2. Phone call to XXX-XXX-2735
 3. SMS passcodes to XXX-XXX-2735

Passcode or option (1-3): 1
Success. Logging you in...

$

If you didn’t already, add a make sync shortcut to your Makefile.

Clean up (from your laptop).

$ hostname
manzana.local
$ pwd
/Users/awdeorio/src/eecs280/p1-stats
$ make clean
rm -rvf *.exe *~ *.out *.dSYM *.stackdump
removed 'main.exe'
removed 'stats_tests.exe'
removed 'stats_public_test.exe'

Copy (from your laptop).

$ hostname
manzana.local
$ pwd
/Users/awdeorio/src/eecs280/p1-stats
$ make sync
rsync \
  -rtv \
  --delete \
  --exclude '.git*' \
  --filter=':- .gitignore' \
  ./ \
  awdeorio@login.engin.umich.edu:p1-stats-copy/
building file list ... done
created directory p1-stats-copy
./
Makefile
main.cpp
main_test.in
main_test.out.correct
main_test_data.tsv
p1_library.cpp
p1_library.h
stats.cpp
stats.h
stats_public_test.cpp
stats_tests.cpp

sent 9557 bytes  received 268 bytes  19650.00 bytes/sec
total size is 8818  speedup is 0.90

Connect to CAEN Linux

Connect to CAEN Linux via ssh. If you’re already connected, you don’t need to connect again.

$ hostname
manzana.local
$ ssh awdeorio@login.engin.umich.edu
Success. Logging you in...
...
$ hostname
caen-vnc-vm16.engin.umich.edu

Change directory to the folder containing your source code. In this tutorial, we’re going to use the copy created by rsync via make sync. Note that you might also have a p1-stats directory created during the Version control on CAEN Linux tutorial.

$ pwd
/home/awdeorio
$ ls
p1-stats p1-stats-copy
$ cd p1-stats-copy
$ pwd
/home/awdeorio/p1-stats-copy

Check style automatically

We’ve provided a make style Makefile target to run all the style checks for you.

$ hostname
caen-vnc-vm16.engin.umich.edu
$ pwd
/home/awdeorio/p1-stats-copy
$ make style
...
EECS 280 style checks PASS

Check style manually

You can run style checks one at a time, manually.

Run cppcheck on all the files that you turn in:

$ hostname
caen-vnc-vm16.engin.umich.edu
$ pwd
/home/awdeorio/p1-stats-copy
$ cppcheck \
    --language=c++ \
    --std=c++11 \
    --error-exitcode=1 \
    stats.cpp \
    stats_tests.cpp \
    main.cpp
Checking main.cpp ...
1/3 files checked 16% done
Checking stats.cpp ...
2/3 files checked 42% done
Checking stats_tests.cpp ...
3/3 files checked 100% done

Run oclint on all the files that you turn in. You’ll need to load a module on CAEN, which adds a tool that isn’t available in the standard environment.

$ hostname
caen-vnc-vm16.engin.umich.edu
$ pwd
/home/awdeorio/p1-stats-copy
$ module load oclint
$ oclint \
    -no-analytics \
    -rule=LongLine \
    -rule=HighNcssMethod \
    -rule=DeepNestedBlock \
    -rule=TooManyParameters \
    -rc=LONG_LINE=90 \
    -rc=NCSS_METHOD=40 \
    -rc=NESTED_BLOCK_DEPTH=4 \
    -rc=TOO_MANY_PARAMETERS=4 \
    -max-priority-1 0 \
    -max-priority-2 0 \
    -max-priority-3 0 \
    stats.cpp \
    stats_tests.cpp \
    main.cpp \
    -- -xc++ --std=c++11

OCLint Report

Summary: TotalFiles=3 FilesWithViolations=0 P1=0 P2=0 P3=0 


[OCLint (http://oclint.org) v0.13]

Run cpd on all files that you turn in. You’ll need to load the pmd module, which contains cpd.

$ hostname
caen-vnc-vm16.engin.umich.edu
$ pwd
/home/awdeorio/p1-stats-copy
$ module load pmd
$ cpd \
    --minimum-tokens 100 \
    --language cpp \
    --failOnViolation true \
    --files \
      stats.cpp \
      stats_tests.cpp \
      main.cpp
Added /home/awdeorio/p1-stats-copy/stats.cpp
Added /home/awdeorio/p1-stats-copy/stats_tests.cpp
Added /home/awdeorio/p1-stats-copy/main.cpp

Next steps

Log out of CAEN.

$ hostname
caen-vnc-vm16.engin.umich.edu
$ exit
$ hostname
manzana.local

Return to the main set up tutorial.