Use of Coverity & Valgrind in Geant4 Gabriele Cosmo.

Slides:



Advertisements
Similar presentations
50.003: Elements of Software Construction Week 6 Thread Safety and Synchronization.
Advertisements

Channel Access Enhancements J. Hill. R3.14 Enhancements Large array support in the portable server –nearly complete –a priority for SNS Port syntax for.
CS492B Analysis of Concurrent Programs Lock Basics Jaehyuk Huh Computer Science, KAIST.
Relaxed Consistency Models. Outline Lazy Release Consistency TreadMarks DSM system.
Object Oriented Programming Elhanan Borenstein Lecture #12 copyrights © Elhanan Borenstein.
Microsoft® Small Basic Debugging Aids Estimated time to complete this lesson: 1 hour.
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
Finding and Debugging Errors
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
Introduction to a Programming Environment
Software Transaction Memory for Dynamic-Sized Data Structures presented by: Mark Schall.
Threads CNS What is a thread?  an independent unit of execution within a process  a "lightweight process"  an independent unit of execution within.
1CMSC 345, Version 4/04 Verification and Validation Reference: Software Engineering, Ian Sommerville, 6th edition, Chapter 19.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
TGDC Meeting, December 2011 Michael Kass National Institute of Standards and Technology Update on SAMATE Automated Source Code Conformance.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Modern Concurrency Abstractions for C# by Nick Benton, Luca Cardelli & C´EDRIC FOURNET Microsoft Research.
University of Palestine software engineering department Testing of Software Systems Fundamentals of testing instructor: Tasneem Darwish.
CS 501: Software Engineering Fall 1999 Lecture 16 Verification and Validation.
Natalia Yastrebova What is Coverity? Each developer should answer to some very simple, yet difficult to answer questions: How do I find new.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 6: User-Defined Functions
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Introduction to Software Testing. Types of Software Testing Unit Testing Strategies – Equivalence Class Testing – Boundary Value Testing – Output Testing.
DEBUGGING. BUG A software bug is an error, flaw, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected.
Games Development 2 Concurrent Programming CO3301 Week 9.
Optimistic Design 1. Guarded Methods Do something based on the fact that one or more objects have particular states  Make a set of purchases assuming.
Axel Naumann. Outline  Static Code Analysis  Coverity  Reporting Tools, Report Quality  "Demo": Examples Axel Naumann Application Area Meeting2.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
Using Model Checking to Find Serious File System Errors StanFord Computer Systems Laboratory and Microsft Research. Published in 2004 Presented by Chervet.
COP-3330: Object Oriented Programming Flow Control May 16, 2012 Eng. Hector M Lugo-Cordero, MS.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
An Undergraduate Course on Software Bug Detection Tools and Techniques Eric Larson Seattle University March 3, 2006.
Debugging of # P. Hristov 04/03/2013. Introduction Difficult problem – The behavior is “random” and depends on the “history” – The debugger doesn’t.
Copyright © Curt Hill The IF Revisited If part 4 Style and Testing.
A FIRST BOOK OF C++ CHAPTER 6 MODULARITY USING FUNCTIONS.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
Geant4 CPU performance : an update Geant4 Technical Forum, CERN, 07 November 2007 J.Apostolakis, G.Cooperman, G.Cosmo, V.Ivanchenko, I.Mclaren, T.Nikitina,
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
Where Testing Fails …. Problem Areas Stack Overflow Race Conditions Deadlock Timing Reentrancy.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
STATIC CODE ANALYSIS. OUTLINE  INTRODUCTION  BACKGROUND o REGULAR EXPRESSIONS o SYNTAX TREES o CONTROL FLOW GRAPHS  TOOLS AND THEIR WORKING  ERROR.
Analyzing Open Source Code February, 2009 David Maxwell Open Source Strategist For Southern California Linux Expo.
Copyright © 2016 Curt Hill Static Code Analysis What it is and does.
Code improvement: Coverity static analysis Valgrind dynamic analysis GABRIELE COSMO CERN, EP/SFT.
Content Coverity Static Analysis Use cases of Coverity Examples
Test 2 Review Outline.
About Me I'm a software Committer on HDFS
Chapter 7: User-Defined Functions II
YAHMD - Yet Another Heap Memory Debugger
Types for Programs and Proofs
Verification and Validation
Chapter 8 – Software Testing
Checking Memory Management
Chapter 18 Software Testing Strategies
Jihyun Park, Changsun Park, Byoungju Choi, Gihun Chang
Design and Programming
Introduction to Static Analyzer
NASA Secure Coding Rules
Release definition & scheduling
Beta releases and Product Management
Problems with Locks Andrew Whitaker CSE451.
“The Little Book on Semaphores” Allen B. Downey
C. M. Overstreet Old Dominion University Fall 2007
Presentation transcript:

Use of Coverity & Valgrind in Geant4 Gabriele Cosmo

Outline Coverity: “triaging” defects Status of Static Code Analysis Use of Vagrind in Geant4 & DRD tool G.Cosmo - Use of Coverity & Valgrind in Geant September 2011

Coverity Static Code Analysis Inspecting only the source code Execution by replacing the compiler Analysis performed on all possible branches of the code Complex and time consuming Identifies defects in the code organizes by type, severity, file/module G.Cosmo - Use of Coverity & Valgrind in Geant September 2011

Coverity: triaging defects The owner specifies an action (performed or to be performed):  Fix required / Fix submitted / Modeling required / Ignore  According to the action, the defect is marked as “triaged”  Statistics will be updated  Defects not fixed will show up again at the next analysis G.Cosmo - Use of Coverity & Valgrind in Geant4 4 Defects are assigned to responsible (owner) The owner can assess and specify the severity:  Major, Moderate, Minor Defects can be flagged as:  Pending / False positive / Intentional / Bug 23 September 2011

Coverity: defects types Memory corruption / illegal accesses Double free, out-of-bound accesses, use-after-delete, … Resource leaks Non virtual destructor, memory leaks, … Uninitialized variables, Unused pointer values, Infinite loops, Missing copy ctors, … API usage errors Non restoring ostream format, using invalid iterator, … Control flow issues Unused/dead code, invalid iterator comparisons, … Incorrect expressions Self-assignment, misuse of enums, … Code organization / performance inefficiencies Recursive headers, hidden parameters, big parameters passed by value, … Security best practices violations  All defect kinds provided with online documentation G.Cosmo - Use of Coverity & Valgrind in Geant September 2011

Use of Coverity in Geant4 New static analysis done after every reference tag Results published immediately after Notification sent to all Category coordinators and to individual developers owning outstanding defects Static analysis applied for all Geant4 libraries Including all possible visualization drivers and optional modules Applied to either sequential or MT mode Could be automated & eventually applied as separate module also to examples/tests G.Cosmo - Use of Coverity & Valgrind in Geant September 2011

Current status in Geant4 Coverity tool introduced to the Collaboration at the 2010 Geant4 Workshop First analysis (after tool upgrade) reported a total of 2753 outstanding defects Status on last reference tag (09-06-ref-09): Outstanding defects: 409 (of which, 370 never triaged) Resolved defects: 2344 G.Cosmo - Use of Coverity & Valgrind in Geant4 7 Goal: ZERO outstanding defects !!! 23 September 2011

Valgrind

Use of Valgrind in Geant4 Selected examples/tests executed for candidate releases and selected reference releases Results published and distributed to Category Coordinators and relevant developers Checks for memory leaks in event loop Difficult now after introduction of MT memory model Run-time errors checks Planning to have them part of regular system testing Recently: checks for run-time race conditions in MT mode Use of embedded DRD tool ( see next slides by A.Dotti ) G.Cosmo - Use of Coverity & Valgrind in Geant September 2011

Valgrind DRD tool Data Race Detection tool Included in the Valgrind suite (use with –tool=drd ) Different types of errors detected: Data races (unprotected possible access to shared resources) Lock contention (checks Mutex locked for too long) Not used in our testing Misuse of POSIX threads e.g. attempt to unlock a Mutex that was not locked,… 23 September 2011 G.Cosmo - Use of Coverity & Valgrind in Geant4 10

Valgrind: Checks for Data Race Tricky part: Two memory operations conflict if different threads refer to the same memory location and at least one is a store No issue if all conflicting operations are ordered by synchronization operations (in Geant4: barriers or locks) MT: all shared objects writes (by master) are protected by barriers or locks or happen before threads are spawned, workers only read shared variables Verified this with FullCMS benchmark: 2 threads, 4 HE pions events, FTFP_BERT DRD tool extremely slow: >48 hours 23 September 2011 G.Cosmo - Use of Coverity & Valgrind in Geant4 11

Valgrind DRD results Few misuse of POSIX libraries (corrected) Try locks of unlocked variables Wrong use of signal/broadcast/wait (causing deadlocks in Mac OSX) Many data race conditions reported Some real concerns: e.g. proper initialization of shared constants in physics models 23 September 2011 G.Cosmo - Use of Coverity & Valgrind in Geant4 12

Scoped static initialization In Geant4 code we have many situations like this: void someFunction() { static G4double someConst = HeavyCalculation(); } This is not thread safe in general See /08/85901.aspx /08/85901.aspx In reality if HeavyCalculation() is “simple” and returns always the same value, we can be safe, but cannot be guaranteed in general DRD reports millions of such cases: luckily only in very few lines of codes called many many times 23 September 2011 G.Cosmo - Use of Coverity & Valgrind in Geant4 13

Conclusions Coverity static analyzer and Valgrind tools regularly used in our development process Efforts to be made to increase automation Lot of progress made since first introduction of Valgrind in 2010 Important to keep going fixing defects and monitoring! Tool also extremely useful in detecting memory leaks Use of Valgrind made for memory checks and MT race condition checks Checks for memory leaks now hard and less effective 23 September 2011 G.Cosmo - Use of Coverity & Valgrind in Geant4 14

Thanks! G.Cosmo - Use of Coverity & Valgrind in Geant September 2011