source: mainline/uspace/app/tester/libext2/libext2_1.c@ 12f9f0d0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 12f9f0d0 was d578fb9, checked in by Martin Sucha <sucha14@…>, 14 years ago

Fixed copyright header in tester/libext2/libext2_1.c

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Sucha
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 <stdio.h>
30#include <unistd.h>
31#include "../tester.h"
32#include "../util.h"
33#include <libext2.h>
34#include <malloc.h>
35
36static ext2_superblock_t *fake_superblock1()
37{
38 uint8_t *buf;
39 int i;
40
41 buf = malloc(EXT2_SUPERBLOCK_SIZE);
42 if (buf == NULL) {
43 return NULL;
44 }
45
46 for (i = 0; i < EXT2_SUPERBLOCK_SIZE; i++) {
47 buf[i] = i % 256;
48 }
49
50 return (ext2_superblock_t *) buf;
51}
52
53const char *test_libext2_1(void)
54{
55 ext2_superblock_t *fake1;
56
57 TPRINTF("Testing libext2 superblock getters...\n");
58 TPRINTF("Simple test for correct position and byte order\n");
59
60 fake1 = fake_superblock1();
61 if (fake1 == NULL) {
62 return "Failed allocating memory for test superblock 1";
63 }
64
65 ASSERT_EQ_32(0x03020100, ext2_superblock_get_total_inode_count(fake1),
66 "Failed getting total inode count");
67 ASSERT_EQ_32(0x07060504, ext2_superblock_get_total_block_count(fake1),
68 "Failed getting total block count");
69 ASSERT_EQ_32(0x0B0A0908, ext2_superblock_get_reserved_block_count(fake1),
70 "Failed getting reserved block count");
71 ASSERT_EQ_32(0x0F0E0D0C, ext2_superblock_get_free_block_count(fake1),
72 "Failed getting free block count");
73 ASSERT_EQ_32(0x13121110, ext2_superblock_get_free_inode_count(fake1),
74 "Failed getting free inode count");
75 ASSERT_EQ_32(0x17161514, ext2_superblock_get_first_block(fake1),
76 "Failed getting first block number");
77 ASSERT_EQ_32(0x1B1A1918, ext2_superblock_get_block_size_log2(fake1),
78 "Failed getting log block size");
79 ASSERT_EQ_32(0x1F1E1D1C, ext2_superblock_get_fragment_size_log2(fake1),
80 "Failed getting log fragment size");
81 ASSERT_EQ_32(0x23222120, ext2_superblock_get_blocks_per_group(fake1),
82 "Failed getting blocks per group");
83 ASSERT_EQ_32(0x27262524, ext2_superblock_get_fragments_per_group(fake1),
84 "Failed getting fragments per group");
85 ASSERT_EQ_32(0x2B2A2928, ext2_superblock_get_inodes_per_group(fake1),
86 "Failed getting inodes per group");
87 ASSERT_EQ_16(0x3938, ext2_superblock_get_magic(fake1),
88 "Failed getting magic number");
89 ASSERT_EQ_16(0x3B3A, ext2_superblock_get_state(fake1),
90 "Failed getting state");
91 ASSERT_EQ_16(0x3F3E, ext2_superblock_get_rev_minor(fake1),
92 "Failed getting minor revision number");
93 ASSERT_EQ_32(0x4B4A4948, ext2_superblock_get_os(fake1),
94 "Failed getting OS");
95 ASSERT_EQ_32(0x4F4E4D4C, ext2_superblock_get_rev_major(fake1),
96 "Failed getting major revision number");
97 ASSERT_EQ_32(0x57565554, ext2_superblock_get_first_inode(fake1),
98 "Failed getting first inode number");
99 ASSERT_EQ_16(0x5958, ext2_superblock_get_inode_size(fake1),
100 "Failed getting size");
101 ASSERT_EQ_8(0x68, fake1->uuid[0], "UUID position is incorrect");
102 ASSERT_EQ_8(0x78, fake1->volume_name[0],
103 "Volume name position is incorrect");
104
105 return NULL;
106}
Note: See TracBrowser for help on using the repository browser.