Subversion Repositories HelenOS

Rev

Rev 2020 | Rev 2050 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (C) 2006 Jakub Jermar
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. #include <test.h>
  30. #include <print.h>
  31. #include <adt/btree.h>
  32. #include <debug.h>
  33.  
  34. #ifdef CONFIG_BENCH
  35. #include <arch/cycle.h>
  36. #endif
  37.  
  38. static void *data = (void *) 0xdeadbeef;
  39.  
  40. void test_btree1(void)
  41. {
  42. #ifdef CONFIG_BENCH
  43.     uint64_t t0 = get_cycle();
  44. #endif
  45.     btree_t t;
  46.     int i;
  47.  
  48.     btree_create(&t);
  49.  
  50.     printf("Inserting keys.\n");
  51.     btree_insert(&t, 19, data, NULL);
  52.     btree_insert(&t, 20, data, NULL);
  53.     btree_insert(&t, 21, data, NULL);
  54.     btree_insert(&t, 0, data, NULL);
  55.     btree_insert(&t, 25, data, NULL);
  56.     btree_insert(&t, 22, data, NULL);
  57.     btree_insert(&t, 26, data, NULL);
  58.     btree_insert(&t, 23, data, NULL);
  59.     btree_insert(&t, 24, data, NULL);
  60.     btree_insert(&t, 5, data, NULL);
  61.     btree_insert(&t, 1, data, NULL);
  62.     btree_insert(&t, 4, data, NULL);
  63.     btree_insert(&t, 28, data, NULL);
  64.     btree_insert(&t, 29, data, NULL);
  65.     btree_insert(&t, 7, data, NULL);
  66.     btree_insert(&t, 8, data, NULL);
  67.     btree_insert(&t, 9, data, NULL);
  68.     btree_insert(&t, 17, data, NULL);
  69.     btree_insert(&t, 18, data, NULL);
  70.     btree_insert(&t, 2, data, NULL);
  71.     btree_insert(&t, 3, data, NULL);
  72.     btree_insert(&t, 6, data, NULL);
  73.     btree_insert(&t, 10, data, NULL);
  74.     btree_insert(&t, 11, data, NULL);
  75.     btree_insert(&t, 12, data, NULL);
  76.     btree_insert(&t, 13, data, NULL);
  77.     btree_insert(&t, 14, data, NULL);
  78.     btree_insert(&t, 15, data, NULL);
  79.     btree_insert(&t, 16, data, NULL);
  80.     btree_insert(&t, 27, data, NULL);
  81.  
  82.     for (i = 30; i < 50; i++)
  83.         btree_insert(&t, i, data, NULL);
  84.     for (i = 100; i >= 50; i--)
  85.         btree_insert(&t, i, data, NULL);
  86.  
  87.     btree_print(&t);
  88.    
  89.     printf("Removing keys.\n");
  90.     btree_remove(&t, 50, NULL);
  91.     btree_remove(&t, 49, NULL);
  92.     btree_remove(&t, 51, NULL);
  93.     btree_remove(&t, 46, NULL);
  94.     btree_remove(&t, 45, NULL);
  95.     btree_remove(&t, 48, NULL);
  96.     btree_remove(&t, 53, NULL);
  97.     btree_remove(&t, 47, NULL);
  98.     btree_remove(&t, 52, NULL);
  99.     btree_remove(&t, 54, NULL);
  100.     btree_remove(&t, 65, NULL);
  101.     btree_remove(&t, 60, NULL);
  102.     btree_remove(&t, 99, NULL);
  103.     btree_remove(&t, 97, NULL);
  104.     btree_remove(&t, 57, NULL);
  105.     btree_remove(&t, 58, NULL);
  106.     btree_remove(&t, 61, NULL);
  107.     btree_remove(&t, 64, NULL);
  108.     btree_remove(&t, 56, NULL);
  109.     btree_remove(&t, 41, NULL);
  110.  
  111.     for (i = 5; i < 20; i++)
  112.         btree_remove(&t, i, NULL);
  113.  
  114.     btree_remove(&t, 2, NULL);
  115.     btree_remove(&t, 43, NULL);
  116.     btree_remove(&t, 22, NULL);
  117.     btree_remove(&t, 100, NULL);
  118.     btree_remove(&t, 98, NULL);
  119.     btree_remove(&t, 96, NULL);
  120.     btree_remove(&t, 66, NULL);
  121.     btree_remove(&t, 1, NULL);
  122.  
  123.     for (i = 70; i < 90; i++)
  124.         btree_remove(&t, i, NULL);
  125.  
  126.     btree_remove(&t, 20, NULL);
  127.     btree_remove(&t, 0, NULL);
  128.     btree_remove(&t, 40, NULL);
  129.     btree_remove(&t, 3, NULL);
  130.     btree_remove(&t, 4, NULL);
  131.     btree_remove(&t, 21, NULL);
  132.     btree_remove(&t, 44, NULL);
  133.     btree_remove(&t, 55, NULL);
  134.     btree_remove(&t, 62, NULL);
  135.     btree_remove(&t, 26, NULL);
  136.     btree_remove(&t, 27, NULL);
  137.     btree_remove(&t, 28, NULL);
  138.     btree_remove(&t, 29, NULL);
  139.     btree_remove(&t, 30, NULL);
  140.     btree_remove(&t, 31, NULL);
  141.     btree_remove(&t, 32, NULL);
  142.     btree_remove(&t, 33, NULL);
  143.     btree_remove(&t, 93, NULL);
  144.     btree_remove(&t, 95, NULL);
  145.     btree_remove(&t, 94, NULL);
  146.     btree_remove(&t, 69, NULL);
  147.     btree_remove(&t, 68, NULL);
  148.     btree_remove(&t, 92, NULL);
  149.     btree_remove(&t, 91, NULL);
  150.     btree_remove(&t, 67, NULL);
  151.     btree_remove(&t, 63, NULL);
  152.     btree_remove(&t, 90, NULL);
  153.     btree_remove(&t, 59, NULL);
  154.     btree_remove(&t, 23, NULL);
  155.     btree_remove(&t, 24, NULL);
  156.     btree_remove(&t, 25, NULL);
  157.     btree_remove(&t, 37, NULL);
  158.     btree_remove(&t, 38, NULL);
  159.     btree_remove(&t, 42, NULL);
  160.     btree_remove(&t, 39, NULL);
  161.     btree_remove(&t, 34, NULL);
  162.     btree_remove(&t, 35, NULL);
  163.     btree_remove(&t, 36, NULL);
  164.  
  165.     btree_print(&t);
  166. #ifdef CONFIG_BENCH
  167.     uint64_t dt = get_cycle() - t0;
  168.     printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
  169. #endif
  170. }
  171.