boottest.c revision 229159
1229159Sadrian/* 2229159Sadrian * Test application for xz_boot.c 3229159Sadrian * 4229159Sadrian * Author: Lasse Collin <lasse.collin@tukaani.org> 5229159Sadrian * 6229159Sadrian * This file has been put into the public domain. 7229159Sadrian * You can do whatever you want with this file. 8229159Sadrian */ 9229159Sadrian 10229159Sadrian#include <stdlib.h> 11229159Sadrian#include <string.h> 12229159Sadrian#include <stdio.h> 13229159Sadrian 14229159Sadrian#define STATIC static 15229159Sadrian#define INIT 16229159Sadrian 17229159Sadrianstatic void error(/*const*/ char *msg) 18229159Sadrian{ 19229159Sadrian fprintf(stderr, "%s\n", msg); 20229159Sadrian} 21229159Sadrian 22229159Sadrian#include "../linux/lib/decompress_unxz.c" 23229159Sadrian 24229159Sadrianstatic uint8_t in[1024 * 1024]; 25229159Sadrianstatic uint8_t out[1024 * 1024]; 26229159Sadrian 27229159Sadrianstatic int fill(void *buf, unsigned int size) 28229159Sadrian{ 29229159Sadrian return fread(buf, 1, size, stdin); 30229159Sadrian} 31229159Sadrian 32229159Sadrianstatic int flush(/*const*/ void *buf, unsigned int size) 33229159Sadrian{ 34229159Sadrian return fwrite(buf, 1, size, stdout); 35229159Sadrian} 36229159Sadrian 37229159Sadrianstatic void test_buf_to_buf(void) 38229159Sadrian{ 39229159Sadrian size_t in_size; 40229159Sadrian int ret; 41229159Sadrian in_size = fread(in, 1, sizeof(in), stdin); 42229159Sadrian ret = decompress(in, in_size, NULL, NULL, out, NULL, &error); 43229159Sadrian /* fwrite(out, 1, FIXME, stdout); */ 44229159Sadrian fprintf(stderr, "ret = %d\n", ret); 45229159Sadrian} 46229159Sadrian 47229159Sadrianstatic void test_buf_to_cb(void) 48229159Sadrian{ 49229159Sadrian size_t in_size; 50229159Sadrian int in_used; 51229159Sadrian int ret; 52229159Sadrian in_size = fread(in, 1, sizeof(in), stdin); 53229159Sadrian ret = decompress(in, in_size, NULL, &flush, NULL, &in_used, &error); 54229159Sadrian fprintf(stderr, "ret = %d; in_used = %d\n", ret, in_used); 55229159Sadrian} 56229159Sadrian 57229159Sadrianstatic void test_cb_to_cb(void) 58229159Sadrian{ 59229159Sadrian int ret; 60229159Sadrian ret = decompress(NULL, 0, &fill, &flush, NULL, NULL, &error); 61229159Sadrian fprintf(stderr, "ret = %d\n", ret); 62229159Sadrian} 63229159Sadrian 64229159Sadrian/* 65229159Sadrian * Not used by Linux <= 2.6.37-rc4 and newer probably won't use it either, 66229159Sadrian * but this kind of use case is still required to be supported by the API. 67229159Sadrian */ 68229159Sadrianstatic void test_cb_to_buf(void) 69229159Sadrian{ 70229159Sadrian int in_used; 71229159Sadrian int ret; 72229159Sadrian ret = decompress(in, 0, &fill, NULL, out, &in_used, &error); 73229159Sadrian /* fwrite(out, 1, FIXME, stdout); */ 74229159Sadrian fprintf(stderr, "ret = %d; in_used = %d\n", ret, in_used); 75229159Sadrian} 76229159Sadrian 77229159Sadrianint main(int argc, char **argv) 78229159Sadrian{ 79229159Sadrian if (argc != 2) 80229159Sadrian fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]); 81229159Sadrian else if (strcmp(argv[1], "bb") == 0) 82229159Sadrian test_buf_to_buf(); 83229159Sadrian else if (strcmp(argv[1], "bc") == 0) 84229159Sadrian test_buf_to_cb(); 85229159Sadrian else if (strcmp(argv[1], "cc") == 0) 86229159Sadrian test_cb_to_cb(); 87229159Sadrian else if (strcmp(argv[1], "cb") == 0) 88229159Sadrian test_cb_to_buf(); 89229159Sadrian else 90229159Sadrian fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]); 91229159Sadrian 92229159Sadrian return 0; 93229159Sadrian} 94