forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sim: add assertions on hostfs copy of structures
hostfs has its copies of some of nuttx definitions with different names to avoid conflicting with the host OS definitions. sometimes people only modifies one of them and forgets updating another. eg. apache#11445 this commit introduces some assertions to detect that kind of mistakes.
- Loading branch information
Showing
3 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/**************************************************************************** | ||
* arch/sim/src/sim/sim_checknuttxtypes.c | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <assert.h> | ||
|
||
/* nuttx types */ | ||
|
||
#include <dirent.h> | ||
#include <sys/statfs.h> | ||
#include <sys/stat.h> | ||
|
||
/* hostfs types */ | ||
|
||
#define __SIM__ | ||
#include <nuttx/fs/hostfs.h> | ||
#undef __SIM__ | ||
|
||
/* Here we make static assertions to ensure nuttx types (eg. struct stat) | ||
* match the corresponding hostfs types. (eg. struct nuttx_stat_s) | ||
* | ||
* TODO: check the alignment as well. (_Alignof) | ||
*/ | ||
|
||
#define STATIC_ASSERT(c) static_assert(c, #c) | ||
#define FIELD(a, b, f) \ | ||
STATIC_ASSERT(offsetof(struct a, f) == offsetof(struct b, f)); \ | ||
STATIC_ASSERT(sizeof(((struct a *)0)->f) == sizeof(((struct b *)0)->f)) | ||
|
||
/* dirent */ | ||
|
||
FIELD(nuttx_dirent_s, dirent, d_type); | ||
FIELD(nuttx_dirent_s, dirent, d_name); | ||
|
||
STATIC_ASSERT(sizeof(struct nuttx_dirent_s) == sizeof(struct dirent)); | ||
|
||
/* stat */ | ||
|
||
FIELD(nuttx_stat_s, stat, st_dev); | ||
FIELD(nuttx_stat_s, stat, st_ino); | ||
FIELD(nuttx_stat_s, stat, st_mode); | ||
FIELD(nuttx_stat_s, stat, st_nlink); | ||
FIELD(nuttx_stat_s, stat, st_uid); | ||
FIELD(nuttx_stat_s, stat, st_gid); | ||
FIELD(nuttx_stat_s, stat, st_rdev); | ||
FIELD(nuttx_stat_s, stat, st_size); | ||
FIELD(nuttx_stat_s, stat, st_atim); | ||
FIELD(nuttx_stat_s, stat, st_mtim); | ||
FIELD(nuttx_stat_s, stat, st_ctim); | ||
FIELD(nuttx_stat_s, stat, st_blksize); | ||
FIELD(nuttx_stat_s, stat, st_blocks); | ||
FIELD(nuttx_stat_s, stat, st_size); | ||
|
||
STATIC_ASSERT(sizeof(struct nuttx_stat_s) == sizeof(struct stat)); | ||
|
||
/* statfs */ | ||
|
||
FIELD(nuttx_statfs_s, statfs, f_type); | ||
FIELD(nuttx_statfs_s, statfs, f_namelen); | ||
FIELD(nuttx_statfs_s, statfs, f_bsize); | ||
FIELD(nuttx_statfs_s, statfs, f_blocks); | ||
FIELD(nuttx_statfs_s, statfs, f_bfree); | ||
FIELD(nuttx_statfs_s, statfs, f_bavail); | ||
FIELD(nuttx_statfs_s, statfs, f_files); | ||
FIELD(nuttx_statfs_s, statfs, f_ffree); | ||
FIELD(nuttx_statfs_s, statfs, f_fsid); | ||
|
||
STATIC_ASSERT(sizeof(struct nuttx_statfs_s) == sizeof(struct statfs)); | ||
|
||
/**************************************************************************** | ||
* Private Functions | ||
****************************************************************************/ | ||
|
||
/* dummy function to suppress nxstyle and compiler warnings */ | ||
|
||
void check_nuttx_types_dummy(void); | ||
|
||
void check_nuttx_types_dummy(void) | ||
{ | ||
} |