Giter VIP home page Giter VIP logo

demo-codes's Introduction

Demo-Codes

Demo Codes for CS253A Course, Link

Demo for gcov tool

This demo needs g++ installed in your system. We pass flags to gcc or g++ as shown below for the file we want to test coverage on.

See the code in coverage.cpp file for more information.

$ g++ -fprofile-arcs -ftest-coverage coverage/coverage.cpp -o coverage

Running the binary produced.

$ ./coverage 
<num1> 
<num2>

or

echo -30 -55 | ./coverage

Run with more example inputs, fuzz it for better coverage.

Using gcov

Use the gcov tool with required flags for more information.

$ gcov -b -c coverage

Output

Check the file *.gcov produced.

File 'cov/coverage.cpp'
Lines executed:100.00% of 11ma
Branches executed:100.00% of 26
Taken at least once:61.54% of 26
Calls executed:100.00% of 10
Creating 'coverage.cpp.gcov'

File '/usr/include/c++/9/iostream'
No executable lines
No branches
No calls
Removing 'iostream.gcov'

Makefile gcov example

See the file in Makefile for more information.

$ make all
$ make cov1
$ make cov2

Clean up

$ make clean 

Installing googletest

You need to clone & install googletest from GitHub. This installation needs cmake & make.

  • Clone the repository googletest.
  • Use [cmake] to generate build & makefiles in the cloned repository.
$ cmake .
$ make -j 12

Alternately use cmake to add all dependencies, see CMakeLists.txt

Running gtests without cmake

You can install googletest framework as described above and then run custom tests using g++/gcc directly without cmake. We show the run of a sample file example1.cpp

$ g++ src/example1.cpp -lgtest -lgtest_main -pthread
$ ./example1

There are three code examples in total.

Running gtests with cmake

Make a build directory and from that build directory, run the following commands Here cmake automatically downloads googletest repository and builds it as a dependency for your cmake project.

Using ninja build.

$  cmake .. -G "Ninja"
$ ninja all
$ ./example1

With make.

$  cmake .. 
$ make -j $(nproc)
$ ./example1

demo-codes's People

Contributors

lahiri-phdworks avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.