Testing C Code … a Short Intro Sufficient Flags

Total Page:16

File Type:pdf, Size:1020Kb

Testing C Code … a Short Intro Sufficient Flags Testing C code … a short intro Sufficient flags -pedantic -Wconversion -Wall -Werror -Wextra -Wstrict-prototypes http://virt08.itu.chalmers.se/mediawiki/index.php/Chapter:C_testing#Compiling_wit h_sufficient_flags Black box “Black-box testing is a method of software testing that examines the functionality of an application without peering into its internal structures or workings. This method of test can be applied to virtually every level of software testing: unit, integration, system and acceptance. It typically comprises most if not all higher level testing, but can also dominate unit testing as well.” https://en.wikipedia.org/wiki/Black-box_testing Unit test “In computer programming, unit testing is a software testing method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine whether they are fit for use.[1] Intuitively, one can view a unit as the smallest testable part of an application. In procedural programming, a unit could be an entire module, but it is more commonly an individual function or procedure.” https://en.wikipedia.org/wiki/Unit_testing max.c int max(int a, int b) { if (a>b) { return a; } return b; } simple-math.c https://github.com/progund/programming-with-c/blob/master/te sting/presentation-material/simple-math.c https://github.com/progund/programming-with-c/blob/master/te sting/presentation-material/simple-math.h Assert - example NOT using assert value = max(13,14); if (value!=14) { printf (" FAILED\n"); …... } printf (" OK\n"); Assert - example using assert printf ("Test max using assert: "); assert (max(13,14)==14); printf (" OK\n"); https://github.com/progund/programming-with-c/blob/master/te sting/presentation-material/assert.c Assert - example using assert $ gcc assert.c simple-math.c -o assert -lm && ./assert Test max using assert: OK Assert - disabling assert in GCC gcc -DNDEBUG assert.c simple-math.c -o assert -lm && ./assert Unit test frameworks - check Check - https://libcheck.github.io/check/ Example: https://github.com/progund/programming-with-c/blob/master/testing/presentation- material/check-max.c Unit test frameworks - check $ gcc check-max.c simple-math.c -lm -lcheck -o check-max && ./check-max Running suite(s): Max Test max using assert: OK 100%: Checks: 1, Failures: 0, Errors: 0 Unit test frameworks - CUnit CUnit - http://cunit.sourceforge.net/ Example: https://github.com/progund/programming-with-c/blob/master/testing/presentation- material/cu-max.c Unit test frameworks - CUnit $ gcc cu-max.c simple-math.c -lcunit -lm -o cu-max && ./cu-max CUnit - A unit testing framework for C - Version 2.1-3 http://cunit.sourceforge.net/ Unit test frameworks - CUnit Suite: Suite_1 Test: test of max() ...Test max using assert: OK passed Run Summary: Type Total Ran Passed Failed Inactive suites 1 1 n/a 0 0 tests 1 1 1 0 0 asserts 1 1 1 0 n/a Elapsed time = 0.000 seconds Code coverage “In computer science, code coverage is a measure used to describe the degree to which the source code of a program is executed when a particular test suite runs. A program with high code coverage, measured as a percentage, has had more of its source code executed during testing which suggests it has a lower chance of containing undetected software bugs compared to a program with low code coverage. Many different metrics can be used to calculate code coverage; some of the most basic are the percent of program subroutines and the percent of program statements called during execution of the test suite.” https://en.wikipedia.org/wiki/Code_coverage Code coverage - gcov $ gcc -fprofile-arcs -ftest-coverage assert.c simple-math.c -o assert -lm $ ./assert $ gcov -b math.c Code coverage - gcov math.c.gcov: -: 43: // Check if the sum fits in an int #####: 44: if ((sum>INT_MAX) || (sum<INT_MIN) ) branch 0 never executed branch 1 never executed branch 2 never executed branch 3 never executed Code coverage - gcov and lcov $ gcc -g --coverage -fprofile-arcs -ftest-coverage assert.c simple-math.c -o assert -lm $ ./assert $ lcov --directory . --capture --output-file simple-math.info $ genhtml -o coverage simple-math.info Test automation “In software testing, test automation is the use of special software (separate from the software being tested) to control the execution of tests and the comparison of actual outcomes with predicted outcomes.[1] Test automation can automate some repetitive but necessary tasks in a formalized testing process already in place, or add additional testing that would be difficult to perform manually. Test automation is critical for continuous testing.” https://en.wikipedia.org/wiki/Test_automation jenkins https://builds.apache.org/.
Recommended publications
  • Software Development Career Pathway
    Career Exploration Guide Software Development Career Pathway Information Technology Career Cluster For more information about NYC Career and Technical Education, visit: www.cte.nyc Summer 2018 Getting Started What is software? What Types of Software Can You Develop? Computers and other smart devices are made up of Software includes operating systems—like Windows, Web applications are websites that allow users to contact management system, and PeopleSoft, a hardware and software. Hardware includes all of the Apple, and Google Android—and the applications check email, share documents, and shop online, human resources information system. physical parts of a device, like the power supply, that run on them— like word processors and games. among other things. Users access them with a Mobile applications are programs that can be data storage, and microprocessors. Software contains Software applications can be run directly from a connection to the Internet through a web browser accessed directly through mobile devices like smart instructions that are stored and run by the hardware. device or through a connection to the Internet. like Firefox, Chrome, or Safari. Web browsers are phones and tablets. Many mobile applications have Other names for software are programs or applications. the platforms people use to find, retrieve, and web-based counterparts. display information online. Web browsers are applications too. Desktop applications are programs that are stored on and accessed from a computer or laptop, like Enterprise software are off-the-shelf applications What is Software Development? word processors and spreadsheets. that are customized to the needs of businesses. Popular examples include Salesforce, a customer Software development is the design and creation of Quality Testers test the application to make sure software and is usually done by a team of people.
    [Show full text]
  • Chapter 1 Introduction to Computers, Programs, and Java
    Chapter 1 Introduction to Computers, Programs, and Java 1.1 Introduction • The central theme of this book is to learn how to solve problems by writing a program . • This book teaches you how to create programs by using the Java programming languages . • Java is the Internet program language • Why Java? The answer is that Java enables user to deploy applications on the Internet for servers , desktop computers , and small hand-held devices . 1.2 What is a Computer? • A computer is an electronic device that stores and processes data. • A computer includes both hardware and software. o Hardware is the physical aspect of the computer that can be seen. o Software is the invisible instructions that control the hardware and make it work. • Computer programming consists of writing instructions for computers to perform. • A computer consists of the following hardware components o CPU (Central Processing Unit) o Memory (Main memory) o Storage Devices (hard disk, floppy disk, CDs) o Input/Output devices (monitor, printer, keyboard, mouse) o Communication devices (Modem, NIC (Network Interface Card)). Bus Storage Communication Input Output Memory CPU Devices Devices Devices Devices e.g., Disk, CD, e.g., Modem, e.g., Keyboard, e.g., Monitor, and Tape and NIC Mouse Printer FIGURE 1.1 A computer consists of a CPU, memory, Hard disk, floppy disk, monitor, printer, and communication devices. CMPS161 Class Notes (Chap 01) Page 1 / 15 Kuo-pao Yang 1.2.1 Central Processing Unit (CPU) • The central processing unit (CPU) is the brain of a computer. • It retrieves instructions from memory and executes them.
    [Show full text]
  • Using the GNU Compiler Collection (GCC)
    Using the GNU Compiler Collection (GCC) Using the GNU Compiler Collection by Richard M. Stallman and the GCC Developer Community Last updated 23 May 2004 for GCC 3.4.6 For GCC Version 3.4.6 Published by: GNU Press Website: www.gnupress.org a division of the General: [email protected] Free Software Foundation Orders: [email protected] 59 Temple Place Suite 330 Tel 617-542-5942 Boston, MA 02111-1307 USA Fax 617-542-2652 Last printed October 2003 for GCC 3.3.1. Printed copies are available for $45 each. Copyright c 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with the Invariant Sections being \GNU General Public License" and \Funding Free Software", the Front-Cover texts being (a) (see below), and with the Back-Cover Texts being (b) (see below). A copy of the license is included in the section entitled \GNU Free Documentation License". (a) The FSF's Front-Cover Text is: A GNU Manual (b) The FSF's Back-Cover Text is: You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development. i Short Contents Introduction ...................................... 1 1 Programming Languages Supported by GCC ............ 3 2 Language Standards Supported by GCC ............... 5 3 GCC Command Options .........................
    [Show full text]
  • Introduction to High Performance Computing
    Introduction to High Performance Computing Shaohao Chen Research Computing Services (RCS) Boston University Outline • What is HPC? Why computer cluster? • Basic structure of a computer cluster • Computer performance and the top 500 list • HPC for scientific research and parallel computing • National-wide HPC resources: XSEDE • BU SCC and RCS tutorials What is HPC? • High Performance Computing (HPC) refers to the practice of aggregating computing power in order to solve large problems in science, engineering, or business. • Purpose of HPC: accelerates computer programs, and thus accelerates work process. • Computer cluster: A set of connected computers that work together. They can be viewed as a single system. • Similar terminologies: supercomputing, parallel computing. • Parallel computing: many computations are carried out simultaneously, typically computed on a computer cluster. • Related terminologies: grid computing, cloud computing. Computing power of a single CPU chip • Moore‘s law is the observation that the computing power of CPU doubles approximately every two years. • Nowadays the multi-core technique is the key to keep up with Moore's law. Why computer cluster? • Drawbacks of increasing CPU clock frequency: --- Electric power consumption is proportional to the cubic of CPU clock frequency (ν3). --- Generates more heat. • A drawback of increasing the number of cores within one CPU chip: --- Difficult for heat dissipation. • Computer cluster: connect many computers with high- speed networks. • Currently computer cluster is the best solution to scale up computer power. • Consequently software/programs need to be designed in the manner of parallel computing. Basic structure of a computer cluster • Cluster – a collection of many computers/nodes. • Rack – a closet to hold a bunch of nodes.
    [Show full text]
  • On the Cognitive Prerequisites of Learning Computer Programming
    On the Cognitive Prerequisites of Learning Computer Programming Roy D. Pea D. Midian Kurland Technical Report No. 18 ON THE COGNITIVE PREREQUISITES OF LEARNING COMPUTER PROGRAMMING* Roy D. Pea and D. Midian Kurland Introduction Training in computer literacy of some form, much of which will consist of training in computer programming, is likely to involve $3 billion of the $14 billion to be spent on personal computers by 1986 (Harmon, 1983). Who will do the training? "hardware and software manu- facturers, management consultants, -retailers, independent computer instruction centers, corporations' in-house training programs, public and private schools and universities, and a variety of consultants1' (ibid.,- p. 27). To date, very little is known about what one needs to know in order to learn to program, and the ways in which edu- cators might provide optimal learning conditions. The ultimate suc- cess of these vast training programs in programming--especially toward the goal of providing a basic computer programming compe- tency for all individuals--will depend to a great degree on an ade- quate understanding of the developmental psychology of programming skills, a field currently in its infancy. In the absence of such a theory, training will continue, guided--or to express it more aptly, misguided--by the tacit Volk theories1' of programming development that until now have served as the underpinnings of programming instruction. Our paper begins to explore the complex agenda of issues, promise, and problems that building a developmental science of programming entails. Microcomputer Use in Schools The National Center for Education Statistics has recently released figures revealing that the use of micros in schools tripled from Fall 1980 to Spring 1983.
    [Show full text]
  • Read the Thesis
    Making compiler tests based on compiler source code coverage Jelle Witsen Elias [email protected] January 19, 2021, 33 pages Academic supervisor: Clemens Grelck, [email protected] Daily supervisors: Jos´eLuis March Cabrelles, [email protected] Remi van Veen, [email protected] Host organisation: Solid Sands, www.solidsands.nl Universiteit van Amsterdam Faculteit der Natuurwetenschappen, Wiskunde en Informatica Master Software Engineering http://www.software-engineering-amsterdam.nl Abstract Compilers are important elements in software infrastructure. It is therefore important that these complex pieces of software are tested. We found a way of making C compiler tests that is different from the usual approach of doing this. With our new process we base new tests on their coverage of compiler source code, instead of constructing them by solely looking at the rules defined in language standards. This way, we manage to make tests with constructions that were overlooked when building our existing compiler test suites. We built a tool that takes source code of a C application as input, along with a C compiler test suite. The tool outputs pieces of code which, when compiled, cover parts of compiler source code that the test suite does not yet cover. With this output, we can construct new tests for inclusion in our existing test suite. Our process is as follows: we take an open source C application and compile its sources with an open source compiler. This compiler has been instrumented to enable source code coverage analysis. After compilation, we compare the coverage of compiler source code of the application with coverage of our existing test suites.
    [Show full text]
  • Software Development a Practical Approach!
    Software Development A Practical Approach! Hans-Petter Halvorsen https://www.halvorsen.blog https://halvorsen.blog Software Development A Practical Approach! Hans-Petter Halvorsen Software Development A Practical Approach! Hans-Petter Halvorsen Copyright © 2020 ISBN: 978-82-691106-0-9 Publisher Identifier: 978-82-691106 https://halvorsen.blog ii Preface The main goal with this document: • To give you an overview of what software engineering is • To take you beyond programming to engineering software What is Software Development? It is a complex process to develop modern and professional software today. This document tries to give a brief overview of Software Development. This document tries to focus on a practical approach regarding Software Development. So why do we need System Engineering? Here are some key factors: • Understand Customer Requirements o What does the customer needs (because they may not know it!) o Transform Customer requirements into working software • Planning o How do we reach our goals? o Will we finish within deadline? o Resources o What can go wrong? • Implementation o What kind of platforms and architecture should be used? o Split your work into manageable pieces iii • Quality and Performance o Make sure the software fulfills the customers’ needs We will learn how to build good (i.e. high quality) software, which includes: • Requirements Specification • Technical Design • Good User Experience (UX) • Improved Code Quality and Implementation • Testing • System Documentation • User Documentation • etc. You will find additional resources on this web page: http://www.halvorsen.blog/documents/programming/software_engineering/ iv Information about the author: Hans-Petter Halvorsen The author currently works at the University of South-Eastern Norway.
    [Show full text]
  • Computer Programming and Database Management - Software Engineering Technology Major (SET)
    Computer Programming and Database Management - Software Engineering Technology Major (SET) Program Chair: Robert (Bob) Nields, MBA • Email: [email protected] • Phone: (513) 569-1653 Co-Op Coordinator Chair: Noelle Grome, ME, MA • Email: [email protected] • Phone: (513) 569-4693 The Computer Programming and Database Management - Software Engineering Technology Major (SET) focuses on the design, development, implementation, and maintenance of software solutions used in a variety of industries and organizations. Students gain practical knowledge and experience in the software development process and methods using relevant, current programming languages, databases, and database query languages. Students also gain knowledge of core math and science concepts and skills. Graduates earn an Associate of Applied Science degree and are prepared to enter the workforce as skilled software developers/computer programmers. Graduates may continue their education in a bachelor's degree program in computer science, engineering technology, or mathematics. Although some required courses are available through evening and/or online classes, most of the required courses for the Software Engineering Technology Major are scheduled as in-person classes offered on Monday through Friday between 8 a.m. and 5 p.m. Employment Options GRADUATE STARTING SALARY Education Options PROJECTIONS: GRADUATES ARE PREPARED TO: $40,000 to $60,000 annual salary STRONG TRANSFER HISTORY: • Design and write computer programs Northern Kentucky University using programming languages NET, EMPLOYMENT OUTLOOK: University of Cincinnati Python, Java, C, and C++ Graduates of the Software Engineering Western Governors University • Develop applications using the Technology program are in demand by Wilmington College Object-Oriented Programming companies locally and nationally. Wright State University Methodology According to the U.S.
    [Show full text]
  • Assignment 10 — 18.11.2020 – V1.2 Dynamic Program Analysis
    SMA: Software Modeling and Analysis Prof. Dr. Oscar Nierstrasz A2020 Pascal Gadient, Pooja Rani Assignment 10 — 18.11.2020 – v1.2 Dynamic Program Analysis Please submit this exercise by email to [email protected] before 25 November 2020, 10:15am. You must submit your code as editable text, i.e., use plain text file(s). Exercise 1: Theory (1 pt) a) Suppose you have an application and you want to test all code paths with dynamic analysis. Is this approach reasonable? Justify! b) Is monkey testing a dynamic analysis technique? Justify! Exercise 2: Contracts (3 pts) In this exercise, we use the syntax and features from jContracts available here. Consider the Java code below. /** * @pre number >= 100.0 * @post return == true * @inv number < 0 || number >= 0 */ public boolean add(int number) f if (number < 10) f this.number = this.number + number; return true; g else f return false; g g a) Are the contracts for add(int number) valid, i.e., exists a configuration that passes all three checks? If yes, which configuration succeeds? If no, what is the problem? b) Can the invariant contract be removed without any side effects? If yes, why do no side-effects occur? If no, which side-effects would occur? c) Suppose you have a Java method that calculates from a given number the number multiplied by itself as shown in the code below. Design a post contract that validates the result, i.e., the contract must be violated whenever a result is wrong. public float square(int number) f return number * number; g page 1 of 5 SMA: Software Modeling and Analysis Prof.
    [Show full text]
  • Computer Programming
    d. Ballpoint pens or sharpened pencils e. Blank notebook paper COMPUTER f. All competitors must create a one-page résumé and submit a hard copy to the PROGRAMMING technical committee chair at orientation. Failure to do so will result in a 10-point penalty. PURPOSE To evaluate each contestant’s preparation for Note: Your contest may also require a hard employment and to recognize outstanding copy of your résumé as part of the actual students for excellence and professionalism in contest. Check the Contest Guidelines the field of computer programming. and/or the updates page on the SkillsUSA website: http://updates.skillsusa.org. First, download and review the General Regulations at: http://updates.skillsusa.org. SCOPE OF THE CONTEST The contest uses competencies identified by the ELIGIBILITY Computing Technology Industry Association. Open to active SkillsUSA members enrolled in The specific projects chosen for national programs with computer programming as the competition will be determined by the occupational objective. Computer Programming technical committee. Knowledge Performance CLOTHING REQUIREMENTS The contest includes a written knowledge test Class E: Contest specific — Business Casual assessing knowledge of Visual Basic, Java, C++ • Official SkillsUSA white polo shirt or RPG or “other approved language.” Check • Black dress slacks (accompanied by black the Contest Guidelines and/or the updates page dress socks or black or skin-tone seamless on the SkillsUSA website: updates.skillsusa.org. hose) or black dress skirt (knee-length, accompanied by black or skin-tone Skill Performance seamless hose) The contest includes a computer programming • Black leather closed-toe dress shoes problem consisting of background information and program specifications with accompanying These regulations refer to clothing items that reference materials and description of program are pictured and described at: output requirements.
    [Show full text]
  • R00456--FM Getting up to Speed
    GETTING UP TO SPEED THE FUTURE OF SUPERCOMPUTING Susan L. Graham, Marc Snir, and Cynthia A. Patterson, Editors Committee on the Future of Supercomputing Computer Science and Telecommunications Board Division on Engineering and Physical Sciences THE NATIONAL ACADEMIES PRESS Washington, D.C. www.nap.edu THE NATIONAL ACADEMIES PRESS 500 Fifth Street, N.W. Washington, DC 20001 NOTICE: The project that is the subject of this report was approved by the Gov- erning Board of the National Research Council, whose members are drawn from the councils of the National Academy of Sciences, the National Academy of Engi- neering, and the Institute of Medicine. The members of the committee responsible for the report were chosen for their special competences and with regard for ap- propriate balance. Support for this project was provided by the Department of Energy under Spon- sor Award No. DE-AT01-03NA00106. Any opinions, findings, conclusions, or recommendations expressed in this publication are those of the authors and do not necessarily reflect the views of the organizations that provided support for the project. International Standard Book Number 0-309-09502-6 (Book) International Standard Book Number 0-309-54679-6 (PDF) Library of Congress Catalog Card Number 2004118086 Cover designed by Jennifer Bishop. Cover images (clockwise from top right, front to back) 1. Exploding star. Scientific Discovery through Advanced Computing (SciDAC) Center for Supernova Research, U.S. Department of Energy, Office of Science. 2. Hurricane Frances, September 5, 2004, taken by GOES-12 satellite, 1 km visible imagery. U.S. National Oceanographic and Atmospheric Administration. 3. Large-eddy simulation of a Rayleigh-Taylor instability run on the Lawrence Livermore National Laboratory MCR Linux cluster in July 2003.
    [Show full text]
  • A Component-Based Software Development Platform for Rapid Prototyping of Embedded Software
    A Component-Based Software Development Platform for Rapid Prototyping of Embedded Software Advisor: Prof. Jun Wu Student: Chong-Fa Hsu A thesis submitted to the Department of Computer Science and Information Engineering of the National Pingtung Institute of Commerce in partial ful¯llment of the requirements for the Degree of Master of Computer Science Information Engineer Pingtung, Taiwan, R.O.C. July 2009 Acknowledgements During these two years, I received a lot of assistance and encouragement from many people. First of all, I must thank my supervisor Prof. Jun Wu. During the composition of the thesis, he provided me with great suggestions and enlightening viewpoints. Although I met with many setbacks which made me dejected in the process of writing this thesis, he always en- couraged me to complete my work. so, without his patient guidance, timely correction, and excellent training, I could not ¯nish the thesis. In particular, I wish to thank my committee members, Dr. Chi-Chou Kao and Dr. Lung-Jen Wang. Their professional corrections and suggestions made the thesis better. Additionally, I would like express my sincere gratitude to Chia-Kang Lin, Chia-Wei Ko, and all real-time system laboratory members in the National Pingtung Institute of Commerce. They always help me whenever I had problems or di±- culties. Finally, I wish to give my deep apprecitation to my family for their endless support and encouragement during these two years. Chong-Fa Hsu Taiwan July 2009 I 摘要 嵌入式軟體的開發與硬體平台有著高度的關聯性,由於嵌入式硬體 的種類逐日成長以及必須縮短上市時間的需求,嵌入式軟體的開發工作 也愈形複雜。為了能縮短嵌入式軟體的上市時間,採用快速應用程式開
    [Show full text]