]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/contrib/xz-embedded/userspace/boottest.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / contrib / xz-embedded / userspace / boottest.c
1 /*
2  * Test application for xz_boot.c
3  *
4  * Author: Lasse Collin <lasse.collin@tukaani.org>
5  *
6  * This file has been put into the public domain.
7  * You can do whatever you want with this file.
8  */
9
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdio.h>
13
14 #define STATIC static
15 #define INIT
16
17 static void error(/*const*/ char *msg)
18 {
19         fprintf(stderr, "%s\n", msg);
20 }
21
22 #include "../linux/lib/decompress_unxz.c"
23
24 static uint8_t in[1024 * 1024];
25 static uint8_t out[1024 * 1024];
26
27 static int fill(void *buf, unsigned int size)
28 {
29         return fread(buf, 1, size, stdin);
30 }
31
32 static int flush(/*const*/ void *buf, unsigned int size)
33 {
34         return fwrite(buf, 1, size, stdout);
35 }
36
37 static void test_buf_to_buf(void)
38 {
39         size_t in_size;
40         int ret;
41         in_size = fread(in, 1, sizeof(in), stdin);
42         ret = decompress(in, in_size, NULL, NULL, out, NULL, &error);
43         /* fwrite(out, 1, FIXME, stdout); */
44         fprintf(stderr, "ret = %d\n", ret);
45 }
46
47 static void test_buf_to_cb(void)
48 {
49         size_t in_size;
50         int in_used;
51         int ret;
52         in_size = fread(in, 1, sizeof(in), stdin);
53         ret = decompress(in, in_size, NULL, &flush, NULL, &in_used, &error);
54         fprintf(stderr, "ret = %d; in_used = %d\n", ret, in_used);
55 }
56
57 static void test_cb_to_cb(void)
58 {
59         int ret;
60         ret = decompress(NULL, 0, &fill, &flush, NULL, NULL, &error);
61         fprintf(stderr, "ret = %d\n", ret);
62 }
63
64 /*
65  * Not used by Linux <= 2.6.37-rc4 and newer probably won't use it either,
66  * but this kind of use case is still required to be supported by the API.
67  */
68 static void test_cb_to_buf(void)
69 {
70         int in_used;
71         int ret;
72         ret = decompress(in, 0, &fill, NULL, out, &in_used, &error);
73         /* fwrite(out, 1, FIXME, stdout); */
74         fprintf(stderr, "ret = %d; in_used = %d\n", ret, in_used);
75 }
76
77 int main(int argc, char **argv)
78 {
79         if (argc != 2)
80                 fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]);
81         else if (strcmp(argv[1], "bb") == 0)
82                 test_buf_to_buf();
83         else if (strcmp(argv[1], "bc") == 0)
84                 test_buf_to_cb();
85         else if (strcmp(argv[1], "cc") == 0)
86                 test_cb_to_cb();
87         else if (strcmp(argv[1], "cb") == 0)
88                 test_cb_to_buf();
89         else
90                 fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]);
91
92         return 0;
93 }