Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 86d0ba4

Browse files
author
Blaine Garst
committed
add unit tests
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@110278 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent dada275 commit 86d0ba4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3199
-0
lines changed

BlocksRuntime/tests/block-static.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// The LLVM Compiler Infrastructure
3+
//
4+
// This file is distributed under the University of Illinois Open Source
5+
// License. See LICENSE.TXT for details.
6+
7+
// testfilerunner CONFIG
8+
9+
#include <stdio.h>
10+
11+
12+
int main(int argc, char **argv) {
13+
static int numberOfSquesals = 5;
14+
15+
^{ numberOfSquesals = 6; }();
16+
17+
if (numberOfSquesals == 6) {
18+
printf("%s: success\n", argv[0]);
19+
return 0;
20+
}
21+
printf("**** did not update static local, rdar://6177162\n");
22+
return 1;
23+
24+
}
25+

BlocksRuntime/tests/blockimport.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// The LLVM Compiler Infrastructure
3+
//
4+
// This file is distributed under the University of Illinois Open Source
5+
// License. See LICENSE.TXT for details.
6+
7+
/*
8+
* blockimport.c
9+
* testObjects
10+
*
11+
* Created by Blaine Garst on 10/13/08.
12+
*
13+
*/
14+
15+
16+
//
17+
// pure C nothing more needed
18+
// CONFIG rdar://6289344
19+
20+
#include <stdio.h>
21+
#include <Block.h>
22+
#include <Block_private.h>
23+
24+
25+
26+
27+
int main(int argc, char *argv[]) {
28+
int i = 1;
29+
int (^intblock)(void) = ^{ return i*10; };
30+
31+
void (^vv)(void) = ^{
32+
if (argc > 0) {
33+
printf("intblock returns %d\n", intblock());
34+
}
35+
};
36+
37+
#if 0
38+
//printf("Block dump %s\n", _Block_dump(vv));
39+
{
40+
struct Block_layout *layout = (struct Block_layout *)(void *)vv;
41+
printf("isa %p\n", layout->isa);
42+
printf("flags %x\n", layout->flags);
43+
printf("descriptor %p\n", layout->descriptor);
44+
printf("descriptor->size %d\n", layout->descriptor->size);
45+
}
46+
#endif
47+
void (^vvcopy)(void) = Block_copy(vv);
48+
Block_release(vvcopy);
49+
printf("%s: success\n", argv[0]);
50+
return 0;
51+
}

BlocksRuntime/tests/byrefaccess.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// The LLVM Compiler Infrastructure
3+
//
4+
// This file is distributed under the University of Illinois Open Source
5+
// License. See LICENSE.TXT for details.
6+
7+
//
8+
// byrefaccess.m
9+
// test that byref access to locals is accurate
10+
// testObjects
11+
//
12+
// Created by Blaine Garst on 5/13/08.
13+
//
14+
// CONFIG
15+
16+
#include <stdio.h>
17+
18+
19+
void callVoidVoid(void (^closure)(void)) {
20+
closure();
21+
}
22+
23+
int main(int argc, char *argv[]) {
24+
__block int i = 10;
25+
26+
callVoidVoid(^{ ++i; });
27+
28+
if (i != 11) {
29+
printf("*** %s didn't update i\n", argv[0]);
30+
return 1;
31+
}
32+
printf("%s: success\n", argv[0]);
33+
return 0;
34+
}

BlocksRuntime/tests/byrefcopy.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// The LLVM Compiler Infrastructure
3+
//
4+
// This file is distributed under the University of Illinois Open Source
5+
// License. See LICENSE.TXT for details.
6+
7+
//
8+
// byrefcopy.m
9+
// testObjects
10+
//
11+
// Created by Blaine Garst on 5/13/08.
12+
//
13+
14+
#include <stdio.h>
15+
#include <Block.h>
16+
#include <Block_private.h>
17+
18+
// CONFIG
19+
20+
void callVoidVoid(void (^closure)(void)) {
21+
closure();
22+
}
23+
24+
int main(int argc, char *argv[]) {
25+
int __block i = 10;
26+
27+
void (^block)(void) = ^{ ++i; };
28+
//printf("original (old style) is %s\n", _Block_dump_old(block));
29+
//printf("original (new style) is %s\n", _Block_dump(block));
30+
void (^blockcopy)(void) = Block_copy(block);
31+
//printf("copy is %s\n", _Block_dump(blockcopy));
32+
// use a copy & see that it updates i
33+
callVoidVoid(block);
34+
35+
if (i != 11) {
36+
printf("*** %s didn't update i\n", argv[0]);
37+
return 1;
38+
}
39+
printf("%s: success\n", argv[0]);
40+
return 0;
41+
}

BlocksRuntime/tests/byrefcopycopy.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// The LLVM Compiler Infrastructure
3+
//
4+
// This file is distributed under the University of Illinois Open Source
5+
// License. See LICENSE.TXT for details.
6+
7+
// CONFIG rdar://6255170
8+
9+
#include <stdio.h>
10+
#include <stdbool.h>
11+
#include <stdlib.h>
12+
#include <Block.h>
13+
#include <Block_private.h>
14+
#include <assert.h>
15+
16+
17+
int
18+
main(int argc, char *argv[])
19+
{
20+
__block int var = 0;
21+
int shouldbe = 0;
22+
void (^b)(void) = ^{ var++; /*printf("var is at %p with value %d\n", &var, var);*/ };
23+
__typeof(b) _b;
24+
//printf("before copy...\n");
25+
b(); ++shouldbe;
26+
size_t i;
27+
28+
for (i = 0; i < 10; i++) {
29+
_b = Block_copy(b); // make a new copy each time
30+
assert(_b);
31+
++shouldbe;
32+
_b(); // should still update the stack
33+
Block_release(_b);
34+
}
35+
36+
//printf("after...\n");
37+
b(); ++shouldbe;
38+
39+
if (var != shouldbe) {
40+
printf("Hmm, var is %d but should be %d\n", var, shouldbe);
41+
return 1;
42+
}
43+
printf("%s: Success!!\n", argv[0]);
44+
45+
return 0;
46+
}

BlocksRuntime/tests/byrefcopyinner.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// The LLVM Compiler Infrastructure
3+
//
4+
// This file is distributed under the University of Illinois Open Source
5+
// License. See LICENSE.TXT for details.
6+
7+
#include <Block.h>
8+
#include <stdio.h>
9+
10+
// CONFIG rdar://6225809
11+
// fixed in 5623
12+
13+
int main(int argc, char *argv[]) {
14+
__block int a = 42;
15+
int* ap = &a; // just to keep the address on the stack.
16+
17+
void (^b)(void) = ^{
18+
//a; // workaround, a should be implicitly imported
19+
Block_copy(^{
20+
a = 2;
21+
});
22+
};
23+
24+
Block_copy(b);
25+
26+
if(&a == ap) {
27+
printf("**** __block heap storage should have been created at this point\n");
28+
return 1;
29+
}
30+
printf("%s: Success\n", argv[0]);
31+
return 0;
32+
}

BlocksRuntime/tests/byrefcopyint.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// The LLVM Compiler Infrastructure
3+
//
4+
// This file is distributed under the University of Illinois Open Source
5+
// License. See LICENSE.TXT for details.
6+
7+
/*
8+
* byrefcopyint.c
9+
* testObjects
10+
*
11+
* Created by Blaine Garst on 12/1/08.
12+
*
13+
*/
14+
15+
//
16+
// byrefcopyid.m
17+
// testObjects
18+
//
19+
// Created by Blaine Garst on 5/13/08.
20+
//
21+
22+
// Tests copying of blocks with byref ints
23+
// CONFIG rdar://6414583 -C99
24+
25+
#include <stdio.h>
26+
#include <string.h>
27+
#include <Block.h>
28+
#include <Block_private.h>
29+
30+
31+
32+
33+
typedef void (^voidVoid)(void);
34+
35+
voidVoid dummy;
36+
37+
void callVoidVoid(voidVoid closure) {
38+
closure();
39+
}
40+
41+
42+
voidVoid testRoutine(const char *whoami) {
43+
__block int dumbo = strlen(whoami);
44+
dummy = ^{
45+
//printf("incring dumbo from %d\n", dumbo);
46+
++dumbo;
47+
};
48+
49+
50+
voidVoid copy = Block_copy(dummy);
51+
52+
53+
return copy;
54+
}
55+
56+
int main(int argc, char *argv[]) {
57+
voidVoid array[100];
58+
for (int i = 0; i < 100; ++i) {
59+
array[i] = testRoutine(argv[0]);
60+
array[i]();
61+
}
62+
for (int i = 0; i < 100; ++i) {
63+
Block_release(array[i]);
64+
}
65+
66+
67+
printf("%s: success\n", argv[0]);
68+
return 0;
69+
}

BlocksRuntime/tests/byrefcopystack.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// The LLVM Compiler Infrastructure
3+
//
4+
// This file is distributed under the University of Illinois Open Source
5+
// License. See LICENSE.TXT for details.
6+
7+
//
8+
// byrefcopystack.m
9+
// testObjects
10+
//
11+
// Created by Blaine Garst on 5/13/08.
12+
//
13+
14+
15+
16+
#include <stdio.h>
17+
#include <Block.h>
18+
19+
// CONFIG rdar://6255170
20+
21+
void (^bumpi)(void);
22+
int (^geti)(void);
23+
24+
void setClosures() {
25+
int __block i = 10;
26+
bumpi = Block_copy(^{ ++i; });
27+
geti = Block_copy(^{ return i; });
28+
}
29+
30+
int main(int argc, char *argv[]) {
31+
setClosures();
32+
bumpi();
33+
int i = geti();
34+
35+
if (i != 11) {
36+
printf("*** %s didn't update i\n", argv[0]);
37+
return 1;
38+
}
39+
printf("%s: success\n", argv[0]);
40+
return 0;
41+
}

0 commit comments

Comments
 (0)