Path: blob/main/sys/contrib/xz-embedded/userspace/boottest.c
48254 views
/*1* Test application for xz_boot.c2*3* Author: Lasse Collin <[email protected]>4*5* This file has been put into the public domain.6* You can do whatever you want with this file.7*/89#include <stdlib.h>10#include <string.h>11#include <stdio.h>1213#define STATIC static14#define INIT1516static void error(/*const*/ char *msg)17{18fprintf(stderr, "%s\n", msg);19}2021/* Disable the CRC64 support even if it was enabled in the Makefile. */22#undef XZ_USE_CRC642324#include "../linux/lib/decompress_unxz.c"2526static uint8_t in[1024 * 1024];27static uint8_t out[1024 * 1024];2829static int fill(void *buf, unsigned int size)30{31return fread(buf, 1, size, stdin);32}3334static int flush(/*const*/ void *buf, unsigned int size)35{36return fwrite(buf, 1, size, stdout);37}3839static void test_buf_to_buf(void)40{41size_t in_size;42int ret;43in_size = fread(in, 1, sizeof(in), stdin);44ret = decompress(in, in_size, NULL, NULL, out, NULL, &error);45/* fwrite(out, 1, FIXME, stdout); */46fprintf(stderr, "ret = %d\n", ret);47}4849static void test_buf_to_cb(void)50{51size_t in_size;52int in_used;53int ret;54in_size = fread(in, 1, sizeof(in), stdin);55ret = decompress(in, in_size, NULL, &flush, NULL, &in_used, &error);56fprintf(stderr, "ret = %d; in_used = %d\n", ret, in_used);57}5859static void test_cb_to_cb(void)60{61int ret;62ret = decompress(NULL, 0, &fill, &flush, NULL, NULL, &error);63fprintf(stderr, "ret = %d\n", ret);64}6566/*67* Not used by Linux <= 2.6.37-rc4 and newer probably won't use it either,68* but this kind of use case is still required to be supported by the API.69*/70static void test_cb_to_buf(void)71{72int in_used;73int ret;74ret = decompress(in, 0, &fill, NULL, out, &in_used, &error);75/* fwrite(out, 1, FIXME, stdout); */76fprintf(stderr, "ret = %d; in_used = %d\n", ret, in_used);77}7879int main(int argc, char **argv)80{81if (argc != 2)82fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]);83else if (strcmp(argv[1], "bb") == 0)84test_buf_to_buf();85else if (strcmp(argv[1], "bc") == 0)86test_buf_to_cb();87else if (strcmp(argv[1], "cc") == 0)88test_cb_to_cb();89else if (strcmp(argv[1], "cb") == 0)90test_cb_to_buf();91else92fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]);9394return 0;95}969798