source: mainline/uspace/app/tester/libext2/libext2_1.c@ 796c276

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 796c276 was 9ffbdf1, checked in by Martin Sucha <sucha14@…>, 15 years ago

Added tests for libext2 superblock getters

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * Copyright (c) 2005 Jakub Vana
3 * Copyright (c) 2005 Jakub Jermar
4 * Copyright (c) 2011 Martin Sucha
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <stdio.h>
32#include <unistd.h>
33#include "../tester.h"
34#include "../util.h"
35#include <libext2.h>
36#include <malloc.h>
37
38static ext2_superblock_t *fake_superblock1()
39{
40 uint8_t *buf;
41 int i;
42
43 buf = malloc(EXT2_SUPERBLOCK_SIZE);
44 if (buf == NULL) {
45 return NULL;
46 }
47
48 for (i = 0; i < EXT2_SUPERBLOCK_SIZE; i++) {
49 buf[i] = i % 256;
50 }
51
52 return (ext2_superblock_t *) buf;
53}
54
55const char *test_libext2_1(void)
56{
57 ext2_superblock_t *fake1;
58
59 TPRINTF("Testing libext2 superblock getters...\n");
60 TPRINTF("Simple test for correct position and byte order\n");
61
62 fake1 = fake_superblock1();
63 if (fake1 == NULL) {
64 return "Failed allocating memory for test superblock 1";
65 }
66
67 ASSERT_EQ_32(0x03020100, ext2_superblock_get_total_inode_count(fake1),
68 "Failed getting total inode count");
69 ASSERT_EQ_32(0x07060504, ext2_superblock_get_total_block_count(fake1),
70 "Failed getting total block count");
71 ASSERT_EQ_32(0x0B0A0908, ext2_superblock_get_reserved_block_count(fake1),
72 "Failed getting reserved block count");
73 ASSERT_EQ_32(0x0F0E0D0C, ext2_superblock_get_free_block_count(fake1),
74 "Failed getting free block count");
75 ASSERT_EQ_32(0x13121110, ext2_superblock_get_free_inode_count(fake1),
76 "Failed getting free inode count");
77 ASSERT_EQ_32(0x17161514, ext2_superblock_get_first_block(fake1),
78 "Failed getting first block number");
79 ASSERT_EQ_32(0x1B1A1918, ext2_superblock_get_block_size_log2(fake1),
80 "Failed getting log block size");
81 ASSERT_EQ_32(0x1F1E1D1C, ext2_superblock_get_fragment_size_log2(fake1),
82 "Failed getting log fragment size");
83 ASSERT_EQ_32(0x23222120, ext2_superblock_get_blocks_per_group(fake1),
84 "Failed getting blocks per group");
85 ASSERT_EQ_32(0x27262524, ext2_superblock_get_fragments_per_group(fake1),
86 "Failed getting fragments per group");
87 ASSERT_EQ_32(0x2B2A2928, ext2_superblock_get_inodes_per_group(fake1),
88 "Failed getting inodes per group");
89 ASSERT_EQ_16(0x3938, ext2_superblock_get_magic(fake1),
90 "Failed getting magic number");
91 ASSERT_EQ_16(0x3B3A, ext2_superblock_get_state(fake1),
92 "Failed getting state");
93 ASSERT_EQ_16(0x3F3E, ext2_superblock_get_rev_minor(fake1),
94 "Failed getting minor revision number");
95 ASSERT_EQ_32(0x4B4A4948, ext2_superblock_get_os(fake1),
96 "Failed getting OS");
97 ASSERT_EQ_32(0x4F4E4D4C, ext2_superblock_get_rev_major(fake1),
98 "Failed getting major revision number");
99 ASSERT_EQ_32(0x57565554, ext2_superblock_get_first_inode(fake1),
100 "Failed getting first inode number");
101 ASSERT_EQ_16(0x5958, ext2_superblock_get_inode_size(fake1),
102 "Failed getting size");
103 ASSERT_EQ_8(0x68, fake1->uuid[0], "UUID position is incorrect");
104 ASSERT_EQ_8(0x78, fake1->volume_name[0],
105 "Volume name position is incorrect");
106
107 return NULL;
108}
Note: See TracBrowser for help on using the repository browser.