Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4758 right-hear 1
/*
2
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
3
* Copyright (c) 2002-2007, Professor Benoit Macq
4
* Copyright (c) 2003-2007, Francois-Olivier Devaux
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
* 1. Redistributions of source code must retain the above copyright
11
*    notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
*    notice, this list of conditions and the following disclaimer in the
14
*    documentation and/or other materials provided with the distribution.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
17
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
* POSSIBILITY OF SUCH DAMAGE.
27
*/
28
 
29
#ifdef _WIN32
30
#include 
31
#endif /* _WIN32 */
32
#include 
33
#include 
34
#include "md5.h"
35
 
36
#define OPJ_Bin_Dir "OPJ_Binaries"
37
 
38
int doprocess(char programme[4096],char command_line[4096]) {
39
 
40
#ifdef _WIN32
41
 
42
	int exit=STILL_ACTIVE;
43
	STARTUPINFO siStartupInfo;
44
	PROCESS_INFORMATION piProcessInfo;
45
 
46
	memset(&siStartupInfo, 0, sizeof(siStartupInfo));
47
	memset(&piProcessInfo, 0, sizeof(piProcessInfo));
48
	siStartupInfo.cb = sizeof(siStartupInfo);
49
 
50
	if(CreateProcess(programme, // Application name
51
		command_line, // Application arguments
52
		0,
53
		0,
54
		FALSE,
55
		CREATE_DEFAULT_ERROR_MODE,
56
		0,
57
		0, // Working directory
58
		&siStartupInfo,
59
		&piProcessInfo) == FALSE)
60
		return 1;
61
 
62
	exit=STILL_ACTIVE;
63
	while(exit==STILL_ACTIVE) {
64
		Sleep(1000);
65
		GetExitCodeProcess(piProcessInfo.hProcess,&exit);
66
	}
67
 
68
	return 0;
69
 
70
#else /* !_WIN32 */
71
	printf("\n%s\n", command_line);
72
	system(command_line);
73
	return 0;
74
 
75
#endif /* _WIN32 */
76
 
77
}
78
 
79
char MD5_process(char *input_filename, char *md5_filename) {
80
	MD5_CTX mdContext;
81
	int bytes;
82
  unsigned char data[1024];
83
	FILE *input_file, *md5_file;
84
 
85
	input_file = fopen(input_filename, "rb");
86
	if (!input_file) {
87
		printf("Error opening file %s\n", input_filename);
88
		return 1;
89
	}
90
 
91
	md5_file = fopen(md5_filename, "wb");
92
	if (!md5_file) {
93
		printf("Error opening file %s\n", md5_filename);
94
		return 1;
95
	}
96
 
97
	MD5Init (&mdContext);
98
  while ((bytes = fread (data, 1, 1024, input_file)) != 0)
99
    MD5Update (&mdContext, data, bytes);
100
  MD5Final (&mdContext);
101
 
102
	fwrite(mdContext.digest,16,1,md5_file);
103
 
104
	fclose(input_file);
105
	fclose(md5_file);
106
 
107
	return 0;
108
}
109
 
110
char fcompare(char *input_filename, char *output_filename) {
111
	FILE *input_file, *output_file;
112
	unsigned char input_buffer[17], output_buffer[17];
113
	char comparison;
114
 
115
	input_file = fopen(input_filename, "rb");
116
	if (!input_file) {
117
		printf("Error opening file %s\n", input_filename);
118
		return -1;
119
	}
120
 
121
	output_file = fopen(output_filename, "rb");
122
	if (!output_file) {
123
		printf("Error opening file %s\n", output_filename);
124
		return -1;
125
	}
126
 
127
	fread(input_buffer,16,1,input_file);
128
	fread(output_buffer,16,1,output_file);
129
	fclose(input_file);
130
	fclose(output_file);
131
	input_buffer[16] = 0;
132
	output_buffer[16] = 0;
133
 
134
	comparison = strcmp(input_buffer, output_buffer);
135
 
136
	if (comparison)
137
		return 1;
138
	return 0;
139
}
140
 
141
int main(int argc, char* argv[]) {
142
	FILE *param_file, *md5_file;
143
	FILE *report_file;
144
	char line[4096];
145
	char md5_filename[4096], tempmd5_filename[4096], temp[4096], report_filename[4096];
146
	char output_filename[4096];
147
	char input_cmdline[4096];
148
	char command_line[4096], exefile[4096];
149
	int task_counter = 0, word_counter;
150
	char bin_dir[4096];
151
	unsigned int word_pointer;
152
	char ch[4096];
153
	char comparison;
154
	int num_failed = 0;
155
	int num_inexistant = 0;
156
	int num_passed = 0;
157
 
158
	if (argc != 3) {
159
		printf("Error with command line. \nExpected: OPJ_Validate parameter_filename bin_directory\n Example: OPJ_Validate parameters_01.txt version1.1.a\n\n");
160
		return 1;
161
	}
162
 
163
	param_file = fopen(argv[1],"rb");
164
	if (!param_file) {
165
		printf("Error opening parameter file %s\n",argv[1]);
166
		return 1;
167
	}
168
 
169
	sprintf(bin_dir,"%s/%s",OPJ_Bin_Dir,argv[2]);
170
	sprintf(tempmd5_filename,"temp/tempmd5.txt");
171
	sprintf(report_filename,"%s/report.txt",bin_dir);
172
	report_file = fopen(report_filename, "wb");
173
	if (!report_file) {
174
		printf("Unable to open report file %s", report_filename);
175
		return 1;
176
	}
177
 
178
	while (fgets(line, 4096, param_file) != NULL) {
179
 
180
		if (line[0] != '#' && line[0] != 0x0d) {	// If not a comment line
181
			sscanf(line, "%s", temp);
182
			word_pointer = 0;
183
			sprintf(input_cmdline,"");
184
			sscanf(line+word_pointer,"%s",ch);
185
			sprintf(exefile,"%s/%s",bin_dir,ch);
186
			word_counter = 0;
187
			while (sscanf(line+word_pointer,"%s",ch) > 0) {
188
				if (word_counter == 4)
189
					strcpy(output_filename, ch);
190
				word_pointer += strlen(ch)+1;
191
				sprintf(input_cmdline,"%s%s ",input_cmdline, ch);
192
				word_counter++;
193
			}
194
			sprintf(md5_filename,"%s.md5",output_filename);
195
			task_counter++;
196
			sprintf(command_line,"%s/%s",bin_dir,input_cmdline);
197
			printf("Task %d\nMD5 file: %s\nCommand line: \"%s\"\n",task_counter, md5_filename,command_line);
198
			fprintf(report_file,"Task %d\n   MD5 file: %s\n   Command line: \"%s\"\n",task_counter, md5_filename,command_line);
199
 
200
			if (doprocess(exefile,command_line)) {
201
				printf("Error executing: \"%s\" \n", command_line);
202
				fprintf(report_file,"Task %d failed because command line is not valid.\n\n", task_counter);
203
			}
204
			else {
205
 
206
				// Check if MD5 reference exists
207
				md5_file = fopen(md5_filename,"rb");
208
				if (md5_file) {
209
					fclose(md5_file);
210
					if (MD5_process(output_filename, tempmd5_filename))
211
						return 1;
212
 
213
					comparison = fcompare(tempmd5_filename, md5_filename);
214
					if (comparison == -1)
215
						return 1;
216
					else if (comparison) {
217
						printf("ERROR: %s and %s are different.\nThe codec seems to behave differently.\n\n", tempmd5_filename, md5_filename);
218
						fprintf(report_file,"ERROR: %s and %s are different.\nThe codec seems to behave differently.\n\n", tempmd5_filename, md5_filename);
219
						num_failed++;
220
					}
221
					else {
222
						printf("%s and %s are the same.\nTask %d OK\n\n",tempmd5_filename, md5_filename, task_counter);
223
						fprintf(report_file,"   %s and %s are the same.\nTask %d OK\n\n",tempmd5_filename, md5_filename, task_counter);
224
						num_passed++;
225
					}
226
					remove(tempmd5_filename);
227
				}
228
				else {
229
					if (MD5_process(output_filename, md5_filename))
230
						return 1;
231
					printf("...  MD5 of %s was inexistant. It has been created\n\n", output_filename);
232
					fprintf(report_file,"MD5 of %s was inexistant. It has been created\n\n", output_filename);
233
					num_inexistant++;
234
				}
235
			}
236
		}
237
	}
238
 
239
	printf("\nREPORT;\n%d tests num_passed\n%d tests num_failed\n%d MD5 were num_inexistant\n", num_passed, num_failed, num_inexistant);
240
	fprintf(report_file,"\nREPORT;\n%d tests num_passed\n%d tests num_failed\n%d MD5 were num_inexistant\n", num_passed, num_failed, num_inexistant);
241
	fclose(param_file);
242
	fclose(report_file);
243
 
244
}