Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 697f9f0

Browse files
committed
Add iteration option to thread test program.
1 parent c7fda55 commit 697f9f0

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/interfaces/ecpg/test/test_thread.pgc

+15-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66

77
#include <pthread.h>
8+
#include <stdlib.h>
89

910
void ins1(void);
1011
void ins2(void);
1112

1213
EXEC SQL BEGIN DECLARE SECTION;
1314
char *dbname;
15+
int iterations = 10;
1416
EXEC SQL END DECLARE SECTION;
1517

1618
int
@@ -22,13 +24,21 @@ EXEC SQL BEGIN DECLARE SECTION;
2224
int rows;
2325
EXEC SQL END DECLARE SECTION;
2426

25-
if (argc != 2)
27+
if (argc < 2 || argc > 3)
2628
{
27-
fprintf(stderr, "Usage: %s dbname\n", argv[0]);
29+
fprintf(stderr, "Usage: %s dbname [iterations]\n", argv[0]);
2830
return 1;
2931
}
3032
dbname = argv[1];
3133

34+
if (argc == 3)
35+
iterations = atoi(argv[2]);
36+
if (iterations % 2 != 0)
37+
{
38+
fprintf(stderr, "iterations must be an even number\n");
39+
return 1;
40+
}
41+
3242
EXEC SQL CONNECT TO:dbname AS test0;
3343

3444
/* DROP might fail */
@@ -47,7 +57,7 @@ EXEC SQL END DECLARE SECTION;
4757
EXEC SQL AT test3 COMMIT WORK;
4858
EXEC SQL DISCONNECT test3;
4959

50-
if (rows == 10)
60+
if (rows == iterations)
5161
printf("Success.\n");
5262
else
5363
printf("Failure.\n");
@@ -61,7 +71,7 @@ ins1(void)
6171
EXEC SQL WHENEVER sqlerror sqlprint;
6272
EXEC SQL CONNECT TO:dbname AS test1;
6373

64-
for (i = 0; i < 5; i++)
74+
for (i = 0; i < iterations / 2; i++)
6575
{
6676
printf("thread 1 : inserting\n");
6777
EXEC SQL AT test1 INSERT INTO test_thread VALUES('thread1');
@@ -82,7 +92,7 @@ ins2(void)
8292
EXEC SQL WHENEVER sqlerror sqlprint;
8393
EXEC SQL CONNECT TO:dbname AS test2;
8494

85-
for (i = 0; i < 5; i++)
95+
for (i = 0; i < iterations / 2; i++)
8696
{
8797
printf("thread 2: inserting\n");
8898
EXEC SQL AT test2 INSERT INTO test_thread VALUES('thread2');

0 commit comments

Comments
 (0)