summaryrefslogtreecommitdiff
path: root/firmware/test/buflib/test_move2.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_move2.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_move2.c')
-rw-r--r--firmware/test/buflib/test_move2.c132
1 files changed, 0 insertions, 132 deletions
diff --git a/firmware/test/buflib/test_move2.c b/firmware/test/buflib/test_move2.c
deleted file mode 100644
index 2f72850b2b..0000000000
--- a/firmware/test/buflib/test_move2.c
+++ /dev/null
@@ -1,132 +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 "core_alloc.h"
23#include "util.h"
24/*
25 * Expected output (64bit)
26--------------------
27after freeing first: available: 10040
28after freeing forth: available: 10040
29buflib_compact(): Compacting!
30move_block(): moving "third"(id=3) by -3210(-25680)
31Move! third, 0x608758, 0x602308, 25680
32Cannot move now for handle 3
33fifth failed. Retrying...
34buflib_compact(): Compacting!
35move_block(): moving "third"(id=3) by -3210(-25680)
36Move! third, 0x608758, 0x602308, 25680
37fifth handle: 1
38fifth(1): 0x608730
39 0x608758
40 21544
41second(2): 0x607308
42 0x607330
43 5160
44third(3): 0x6022e0
45 0x602308
46 15400
47sixth(4): 0x605f08
48 0x605f30
49 2088
50seventh(5): 0x606730
51 0x606758
52 552
530x6022e0: val: 1925 (third)
540x605f08: val: 261 (sixth)
550x606730: val: 69 (seventh)
560x606958: val: -310 (<unallocated>)
570x607308: val: 645 (second)
580x608730: val: 2693 (fifth)
59--------------------
60*/
61
62static int move_size, retry;
63int move_callback(int handle, void* old, void* new)
64{
65 move_size = (char*)old-(char*)new;
66 printf("Move! %s, %p, %p, %d\n", core_get_name(handle), old, new,
67 move_size);
68
69 if (!retry)
70 {
71 retry = 1;
72 printf("Cannot move now for handle %d\n", handle);
73 return BUFLIB_CB_CANNOT_MOVE;
74 }
75 return BUFLIB_CB_OK;
76}
77
78struct buflib_callbacks ops = {
79 .move_callback = move_callback,
80 .shrink_callback = NULL,
81};
82
83static struct buflib_callbacks ops_no_move = {
84 .move_callback = NULL,
85 .shrink_callback = NULL,
86};
87
88int main(void)
89{
90 UT_core_allocator_init();
91
92 int first = core_alloc("first", 20<<10);
93 int second= core_alloc_ex("second", 5<<10, &ops_no_move);
94 int third = core_alloc_ex("third", 15<<10, &ops);
95 strcpy(core_get_data(second), "Here's data");
96
97 core_free(first);
98 printf("after freeing first: available: %zu\n", core_available());
99 /* should not trigger compaction, but replace the just freed one */
100 int fourth = core_alloc("forth", 20<<10);
101 core_free(fourth);
102 printf("after freeing forth: available: %zu\n", core_available());
103 /* should trigger compaction since it's a bit bigger than the just freed one */
104 int fifth = core_alloc("fifth", 21<<10);
105 if (fifth <= 0)
106 {
107 printf("fifth failed. Retrying...\n");
108 fifth = core_alloc("fifth", 21<<10);
109 }
110 if (fifth <= 0)
111 {
112 printf("fifth still failed\n");
113 }
114
115 printf("fifth handle: %d\n", fifth);
116 int sixth = core_alloc("sixth", 2<<10);
117 int seventh = core_alloc("seventh", 512);
118
119
120 core_print_allocs(&print_simple);
121 core_print_blocks(&print_simple);
122 int ret = !(!strcmp(core_get_data(second), "Here's data") && move_size >= 20<<10);
123
124 core_free(second);
125 core_free(third);
126 if (fifth > 0)
127 core_free(fifth);
128 core_free(sixth);
129 core_free(seventh);
130
131 return ret;
132}