Commit 9456ded2 by René

2023: gcc code coverage

parents
Showing with 114 additions and 0 deletions
.vscode/
*.c.gcov
*.c.gcda
*.c.gcno
*.gcov
*.gcda
*.gcno
multi
*.o
\ No newline at end of file
CC=gcc
GCOV_FLAGS=-fprofile-arcs -ftest-coverage
SOURCE1=multi
SOURCE2=fun
SOURCES=$(SOURCE1).c $(SOURCE2).c
TARGET=multi
$(TARGET): $(SOURCES)
$(CC) $(GCOV_FLAGS) $(SOURCES) -o $(TARGET)
run: $(TARGET)
./$(TARGET)
coverage: $(TARGET)
gcov $(SOURCE1).c
gcov $(SOURCE2).c
details: $(TARGET)
cat $(SOURCE1).c.gcov
cat $(SOURCE2).c.gcov
clean: $(TARGET).*
rm $(TARGET) $(SOURCE1).gcno $(SOURCE2).gcno $(SOURCE1).gcda $(SOURCE2).gcda $(SOURCE1).c.gcov $(SOURCE2).c.gcov
#include <stdio.h>
void getMenu() {
printf("Enter your choice:\n");
printf("\t0 -- exit\n");
printf("\t1 -- task 1\n");
printf("\t2 -- task 2\n");
printf("\t3 -- task 3\n");
}
int getChoice() {
int c;
getMenu();
scanf("%d",&c);
return c;
}
void task1() {
int a, b;
a = 12;
b = 5;
printf("a %% b = %d\n", a%b);
}
void task2() {
int a, b;
a = 12;
b = 5;
printf("a - b = %d\n", a-b);
}
void task3() {
int a, b;
a = 12;
b = 5;
printf("a + b = %d\n", a-b);
}
void task4() {
int a, b;
a = 12;
b = 5;
printf("a * b = %d\n", a*b);
}
\ No newline at end of file
#ifndef __FUN__H__
#define __FUN__H__
int getChoice();
void task1();
void task2();
void task3();
void task4();
#endif
\ No newline at end of file
#include <stdio.h>
#include "fun.h"
int main(void) {
int choice;
int done;
done = 0;
do {
choice = getChoice();
switch (choice) {
case 0:
done = 1;
break;
case 1: task1();
case 2: task2(); break;
case 3: task3(); break;
case 5: break;
default:
done = 1;
break;
}
} while (!done);
return 0;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment