first and last commit
This commit is contained in:
commit
1bf4efd552
2612 files changed
+636500
No files matched your search
@@ -0,0 +1,62 @@
|
||||
#include <unittest.h>
|
||||
#include <lib/blockdev.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
struct mock_blockdev {
|
||||
struct blockdev bdev;
|
||||
|
||||
/* local data */
|
||||
FILE *backing;
|
||||
};
|
||||
|
||||
static int mock_blockdev_read_block(struct blockdev *bdev, void *ptr, block_addr block, uint32_t count)
|
||||
{
|
||||
struct mock_blockdev *mdev = (struct mock_blockdev *)bdev;
|
||||
int result;
|
||||
|
||||
#if !NO_MOCK_ASSERTS
|
||||
// no overflow
|
||||
TEST_ASSERT_GTE(block + count, block);
|
||||
|
||||
// buffer must be properly aligned
|
||||
TEST_ASSERT_EQ((uintptr_t)ptr & (bdev->alignment - 1), 0);
|
||||
|
||||
TEST_ASSERT_GT(count, 0u);
|
||||
TEST_ASSERT_LT(block, mdev->bdev.block_count);
|
||||
TEST_ASSERT_LTE(block + count, mdev->bdev.block_count);
|
||||
#endif
|
||||
|
||||
result = fseek(mdev->backing, block << mdev->bdev.block_shift, SEEK_SET);
|
||||
#if !NO_MOCK_ASSERTS
|
||||
TEST_ASSERT_EQ(result, 0);
|
||||
#endif
|
||||
result = fread(ptr, 1 << mdev->bdev.block_shift, count, mdev->backing);
|
||||
#if !NO_MOCK_ASSERTS
|
||||
TEST_ASSERT_EQ(result, count);
|
||||
#endif
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
struct blockdev *create_mock_blockdev(const char *name, const char *filename, uint32_t block_size)
|
||||
{
|
||||
struct mock_blockdev *mdev;
|
||||
struct stat st;
|
||||
FILE *f;
|
||||
int result;
|
||||
|
||||
result = stat(filename, &st);
|
||||
TEST_ASSERT_EQ(result, 0);
|
||||
|
||||
f = fopen(filename, "r");
|
||||
TEST_ASSERT_NOT_NULL(f);
|
||||
|
||||
mdev = malloc(sizeof(struct mock_blockdev));
|
||||
|
||||
construct_blockdev(&mdev->bdev, name, st.st_size, block_size);
|
||||
mdev->backing = f;
|
||||
mdev->bdev.read_block_hook = &mock_blockdev_read_block;
|
||||
|
||||
return &mdev->bdev;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Apple Inc. All rights reserved.
|
||||
*
|
||||
* This document is the property of Apple Inc.
|
||||
* It is considered confidential and proprietary.
|
||||
*
|
||||
* This document may not be reproduced or transmitted in any form,
|
||||
* in whole or in part, without the express written permission of
|
||||
* Apple Inc.
|
||||
*/
|
||||
#include <sys.h>
|
||||
#include <unittest.h>
|
||||
|
||||
static int irq_disable_count;
|
||||
|
||||
#if DEBUG_CRITICAL_SECTIONS
|
||||
void _enter_critical_section(const char *from)
|
||||
{
|
||||
#else
|
||||
void enter_critical_section(void)
|
||||
{
|
||||
#endif
|
||||
irq_disable_count++;
|
||||
}
|
||||
|
||||
#if DEBUG_CRITICAL_SECTIONS
|
||||
void _exit_critical_section(const char *from)
|
||||
{
|
||||
#else
|
||||
void exit_critical_section(void)
|
||||
{
|
||||
#endif
|
||||
TEST_ASSERT_GT(irq_disable_count, 0);
|
||||
irq_disable_count--;
|
||||
}
|
||||
|
||||
void reset_critical_section(void)
|
||||
{
|
||||
irq_disable_count = 0;
|
||||
}
|
||||
|
||||
TEST_SETUP_HOOK(reset_critical_section);
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
bool security_allow_memory(const void *address, size_t length)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool security_allow_modes(uint32_t modes)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
#include <list.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <lib/syscfg.h>
|
||||
|
||||
struct mock_syscfg_value {
|
||||
struct list_node list_node;
|
||||
|
||||
struct syscfgMemEntry entry;
|
||||
};
|
||||
|
||||
struct list_node mock_syscfg_list = LIST_INITIAL_VALUE(mock_syscfg_list);
|
||||
|
||||
void mock_syscfg_add(uint32_t tag, void *data, uint32_t size)
|
||||
{
|
||||
struct mock_syscfg_value *new_value;
|
||||
|
||||
new_value = calloc(1, sizeof(*new_value));
|
||||
new_value->entry.seTag = tag;
|
||||
new_value->entry.seDataSize = size;
|
||||
// store the pointer itself in the array for inline data... dirty but it works
|
||||
memcpy(new_value->entry.seData, &data, sizeof(data));
|
||||
|
||||
list_add_tail(&mock_syscfg_list, &new_value->list_node);
|
||||
}
|
||||
|
||||
void mock_syscfg_reset(void)
|
||||
{
|
||||
struct mock_syscfg_value *value;
|
||||
|
||||
while ((value = list_remove_tail_type(&mock_syscfg_list, struct mock_syscfg_value, list_node)) != NULL) {
|
||||
free(value);
|
||||
}
|
||||
}
|
||||
|
||||
bool syscfgFindByTag(uint32_t tag, struct syscfgMemEntry *entry)
|
||||
{
|
||||
struct mock_syscfg_value *value;
|
||||
|
||||
list_for_every_entry(&mock_syscfg_list, value, struct mock_syscfg_value, list_node) {
|
||||
if (value->entry.seTag == tag) {
|
||||
memcpy(entry, &value->entry, sizeof(*entry));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void *syscfgGetData(struct syscfgMemEntry *entry)
|
||||
{
|
||||
void *ptr;
|
||||
|
||||
memcpy(&ptr, entry->seData, sizeof(ptr));
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
uint32_t syscfgGetSize(struct syscfgMemEntry *entry)
|
||||
{
|
||||
return entry->seDataSize;
|
||||
}
|
||||
|
||||
bool
|
||||
syscfg_find_tag(uint32_t tag, void **data_out, uint32_t *size_out)
|
||||
{
|
||||
static struct syscfgMemEntry result;
|
||||
|
||||
if (syscfgFindByTag(tag, &result)) {
|
||||
if (data_out) {
|
||||
*data_out = syscfgGetData(&result);
|
||||
}
|
||||
if (size_out) {
|
||||
*size_out = syscfgGetSize(&result);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user