summaryrefslogtreecommitdiff
path: root/firmware/test/buflib/test_shrink_cb.c
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2020-07-15 19:40:55 -0400
committerSolomon Peachy <pizza@shaftnet.org>2020-07-24 21:20:13 +0000
commit092c340a2062fa98b7387fc5fd63578ddae7d0b6 (patch)
tree98ec96946eeb2ae709cb0528cc6998e21bb9b290 /firmware/test/buflib/test_shrink_cb.c
parent17f7cc92c258bc456a27c3e7c5a19c9409851879 (diff)
downloadrockbox-092c340a2062fa98b7387fc5fd63578ddae7d0b6.tar.gz
rockbox-092c340a2062fa98b7387fc5fd63578ddae7d0b6.zip
[1/4] Remove SH support and all archos targets
This removes all code specific to SH targets Change-Id: I7980523785d2596e65c06430f4638eec74a06061
Diffstat (limited to 'firmware/test/buflib/test_shrink_cb.c')
-rw-r--r--firmware/test/buflib/test_shrink_cb.c108
1 files changed, 0 insertions, 108 deletions
diff --git a/firmware/test/buflib/test_shrink_cb.c b/firmware/test/buflib/test_shrink_cb.c
deleted file mode 100644
index 8c2c02ed1c..0000000000
--- a/firmware/test/buflib/test_shrink_cb.c
+++ /dev/null
@@ -1,108 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2011 Thomas Martitz
11*
12* This program is free software; you can redistribute it and/or
13* modify it under the terms of the GNU General Public License
14* as published by the Free Software Foundation; either version 2
15* of the License, or (at your option) any later version.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21#include <stdio.h>
22#include <stdlib.h>
23#include "core_alloc.h"
24#include "util.h"
25
26/*
27 * Expected output (64-bit):
28-------------------
29MOVED!
300x6032e0: val: 1285 (first)
310x605b08: val: 1285 (third)
320x608330: val: 1413 (fourth)
330x60af58: val: 2181 (fifth)
34SHRINK! 517
35MOVED!
360x6032e0: val: 1285 (first)
370x605b08: val: 645 (third)
380x606f30: val: 1413 (fourth)
390x609b58: val: 2181 (fifth)
400x60df80: val: 517 (sixth)
41-------------------
42*/
43
44#define error(...) do { printf(__VA_ARGS__); exit(1); } while(0)
45static int move_callback(int handle, void* old, void* new)
46{
47 printf("MOVED!\n");
48 return BUFLIB_CB_OK;
49}
50
51static int shrink_callback(int handle, unsigned hints, void* start, size_t size)
52{
53 char* buf = start;
54 size /= 2;
55
56 printf("SHRINK! %u\n", hints);
57
58 memmove(buf + size/2, buf, size);
59 if (core_shrink(handle, buf + size/2, size))
60 {
61 return BUFLIB_CB_OK;
62 }
63 return BUFLIB_CB_CANNOT_SHRINK;
64}
65
66struct buflib_callbacks ops = {
67 .move_callback = move_callback,
68 .shrink_callback = shrink_callback,
69};
70
71int main(void)
72{
73 UT_core_allocator_init();
74
75 int first = core_alloc("first", 10<<10);
76 int second = core_alloc("second", 10<<10);
77 int third = core_alloc_ex("third", 10<<10, &ops);
78
79 strcpy(core_get_data(third), "third");
80
81 core_free(second);
82 int fourth = core_alloc("fourth", 11<<10);
83 strcpy(core_get_data(fourth), "fourth");
84
85 /* this should cause MOVED! twice */
86 int fifth = core_alloc("fifth", 17<<10);
87 if (fifth <= 0) error("fifth failed\n");
88 strcpy(core_get_data(fifth), "fifth");
89
90 core_print_blocks(&print_simple);
91 int sixth = core_alloc("sixth", 4<<10);
92 if (sixth <= 0) error("sixth failed\n");
93 strcpy(core_get_data(sixth), "sixth");
94
95 core_print_blocks(&print_simple);
96
97 int ret = strcmp(core_get_data(third), "third")
98 || strcmp(core_get_data(fourth), "fourth")
99 || strcmp(core_get_data(fifth), "fifth")
100 || strcmp(core_get_data(sixth), "sixth");
101 core_free(first);
102 core_free(third);
103 core_free(fourth);
104 core_free(fifth);
105 core_free(sixth);
106
107 return ret;
108}