-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
156 lines (136 loc) · 5.48 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
SHELL=/bin/bash
CC = gcc
CFLAGS= -Wall -Werror -Wextra -g
TCOV = -fprofile-arcs -ftest-coverage
BIN = $(patsubst %.c,%,$(wildcard *.c))
TESTS = checkarg checkfile checkline checkcolumn checkdiag checksig checksize checkmemory
TESTSUP = checkname checkcov
.PHONY: all
all : $(BIN) $(TESTS) $(TESTSUP)
clean :
@/bin/rm -f *.o *~ $(BIN)
scriptline:
@echo "#!/bin/bash" > scriptl.sh
@echo "magic=0" >> scriptl.sh
@echo 'result=`echo "$$1*($$1*$$1+1)/2" | bc`' >> scriptl.sh
@echo "while read line; do" >> scriptl.sh
@echo ' for i in $$line; do' >> scriptl.sh
@echo ' magic=$$(($$magic + $$i))' >> scriptl.sh
@echo " done" >> scriptl.sh
@echo ' if [ $$magic -ne $$result ]; then' >> scriptl.sh
@echo " exit 1" >> scriptl.sh
@echo " fi" >> scriptl.sh
@echo " magic=0" >> scriptl.sh
@echo "done < result" >> scriptl.sh
@chmod +x scriptl.sh
scriptcolumn:
@echo "#!/bin/bash" > scriptc.sh
@echo "magic=0" >> scriptc.sh
@echo 'result=`echo "$$1*($$1*$$1+1)/2" | bc`' >> scriptc.sh
@echo 'for i in `seq 1 $$1`; do' >> scriptc.sh
@echo " magic=0 " >> scriptc.sh
@echo ' c=`cat result | cut -d " " -f$$i`' >> scriptc.sh
@echo ' for j in $$c; do' >> scriptc.sh
@echo ' magic=$$(($$magic + $$j))' >> scriptc.sh
@echo " done" >> scriptc.sh
@echo ' if [ $$magic -ne $$result ] ;then' >> scriptc.sh
@echo " exit 1" >> scriptc.sh
@echo " fi" >> scriptc.sh
@echo "done" >> scriptc.sh
@chmod +x scriptc.sh
scriptdiag:
@echo "#!/bin/bash" > scriptd.sh
@echo 'result=`echo "$$1*($$1*$$1+1)/2" | bc`' >> scriptd.sh
@echo "i=1" >> scriptd.sh
@echo 'j=$$1' >> scriptd.sh
@echo "magic1=0" >> scriptd.sh
@echo "magic2=0" >> scriptd.sh
@echo "while read line; do" >> scriptd.sh
@echo ' c=`echo $$line | cut -d " " -f$$i`' >> scriptd.sh
@echo ' magic1=$$(($$magic1 + $$c))' >> scriptd.sh
@echo ' c=`echo $$line | cut -d " " -f$$j`' >> scriptd.sh
@echo ' magic2=$$(($$magic2 + $$c))' >> scriptd.sh
@echo ' i=$$(($$i + 1))' >> scriptd.sh
@echo ' j=$$(($$j - 1))' >> scriptd.sh
@echo "done < result" >> scriptd.sh
@echo 'if [ $$magic1 -ne $$result -o $$magic2 -ne $$result ]; then' >> scriptd.sh
@echo " exit 1" >> scriptd.sh
@echo "fi" >> scriptd.sh
@chmod +x scriptd.sh
checkarg:
@echo "[32m################### TESTING: args[0m"
./$(BIN) 16 2> /dev/null || exit 0 && exit 1
./$(BIN) 5 2> /dev/null || exit 0 && exit 1
./$(BIN) "-6" 2> /dev/null || exit 0 && exit 1
@echo -e "[32m################### TESTING: passed\n[0m"
checkfile:
@echo "[32m################### TESTING: numbers of lines and columns[0m"
./$(BIN) 6 > result && test $$(wc -l < result) -ne 6 && exit 1 || exit 0
test $$(wc -w < result) -ne 36 && exit 1 || exit 0
./$(BIN) 26 > result && test $$(wc -l < result) -ne 26 && exit 1 || exit 0
test $$(wc -w < result) -ne 676 && exit 1 || exit 0
@echo -e "[32m################### TESTING: passed\n[0m"
checkline: scriptline
@echo "[32m################### TESTING: lines give the magic number[0m"
./$(BIN) 6 > result && ./scriptl.sh 6 || exit 1
./$(BIN) 10 > result && ./scriptl.sh 10 || exit 1
./$(BIN) 26 > result && ./scriptl.sh 26 || exit 1
@rm scriptl.sh ; rm result
@echo -e "[32m################### TESTING: passed\n[0m"
checkcolumn: scriptcolumn
@echo "[32m################### TESTING: columns give the magic number[0m"
./$(BIN) 6 > result && ./scriptc.sh 6 || exit 1
./$(BIN) 10 > result && ./scriptc.sh 10 || exit 1
./$(BIN) 26 > result && ./scriptc.sh 26 || exit 1
@rm scriptc.sh ; rm result
@echo -e "[32m################### TESTING: passed\n[0m"
checkdiag: scriptdiag
@echo "[32m################### TESTING: diagonals give the magic number[0m"
./$(BIN) 6 > result && ./scriptd.sh 6 || exit 1
./$(BIN) 10 > result && ./scriptd.sh 10 || exit 1
./$(BIN) 26 > result && ./scriptd.sh 26 || exit 1
@rm scriptd.sh ; rm result
@echo -e "[32m################### TESTING: passed\n[0m"
checksig:
@echo "[32m################### TESTING: sync with signal[0m"
for i in $$(seq 0 1000) ; do ./$(BIN) 6 > /dev/null ; done
@echo -e "[32m################### TESTING: passed\n[0m"
checksize:
@echo "[32m################### TESTING: large square[0m"
./$(BIN) 1002 > /dev/null || exit 1
./$(BIN) 1000002 2> /dev/null || exit 0 && exit 1
@echo -e "[32m################### TESTING: passed\n[0m"
checkmemory:
@echo "[32m################### TESTING: memory leak or error[0m"
valgrind --leak-check=full --trace-children=yes --error-exitcode=1 ./$(BIN) 1002 > /dev/null 2>&1 || exit 1
@echo -e "[32m################### TESTING: passed\n[0m"
# Ajoutez vos tests ici
scriptname:
@echo "#!/bin/bash" > scriptname.sh
@echo 'if [ ! -f "magicsquare" ]; then' >>scriptname.sh
@echo 'exit 1' >>scriptname.sh
@echo 'fi ' >>scriptname.sh
@chmod +x scriptname.sh
checkname: scriptname
@echo "[32m################### TESTING : name of program[0m"
./scriptname.sh || exit 1
@rm scriptname.sh
@echo -e "[32m################### TESTING: passed\n[0m"
scriptcov:
@echo "#!/bin/bash" > scriptcov.sh
@echo "pourc=60" >>scriptcov.sh
@echo './a.out 6' >>scriptcov.sh
@echo 'ab=$$(gcov ./magicsquare.c | grep -o -E ":[0-9][0-9]" |sed "s/://") ' >>scriptcov.sh
@echo 'if [ $$ab -lt $$pourc ]; then ' >> scriptcov.sh
@echo 'exit 1; fi' >> scriptcov.sh
@chmod +x scriptcov.sh
checkcov: scriptcov
@echo "[32m################### TESTING : code coverage[0m"
$(CC) $(CFLAGS) $(TCOV) magicsquare.c
./scriptcov.sh || exit 1
@rm scriptcov.sh
@rm magicsquare.c.gcov
@rm magicsquare.gcda
@rm magicsquare.gcno
@rm a.out
@echo -e "[32m################### TESTING: passed\n[0m"