jingfei195887 opened a new pull request, #22529:
URL: https://github.com/apache/nuttx/pull/22529

   ## Summary
   
   RPMSG clients currently keep separate ioctl argument-size tables. A command 
implemented by the remote device can therefore reach it through one transport 
and return `ENOTTY` through another. Add `ioctl_arglen(cmd, arg)` for 
contiguous device arguments and use it in rpmsgfs, rpmsgdev, rpmsgblk and 
rpmsgmtd.
   
   Keep local FIONBIO, geometry operations, SMART/MMC requests and configdata 
marshalling in their existing paths. The common table follows the device 
contracts for immediate framebuffer power, boolean battery-online and integer 
battery-protocol arguments. Clients check that the argument fits their transmit 
buffer before copying it. The filesystem documentation describes the helper's 
contract and limits.
   
   ## Impact
   
   - Feature: YES. The four clients share support for the listed contiguous 
ioctl arguments; the remote device still decides whether a command is supported.
   - User adaptation: NO. Existing ioctl calling conventions remain in place. 
This adds an internal sizing API, not a new syscall.
   - Build process: NO changes. No Kconfig options or wire structures change.
   - Drivers: YES, the four RPMSG client paths above. Hardware-specific drivers 
and server dispatch are unchanged.
   - Documentation: YES, API contract and transport-specific exceptions are 
documented.
   - Security: no new trust boundary is introduced. The helper requires 
accessible caller-provided buffers; it does not validate pointers or provide 
nested-pointer marshalling.
   - Compatibility: existing specialized paths are retained. Unknown commands 
still return `ENOTTY`; an argument exceeding the transmit capacity returns 
`EMSGSIZE`. Heterogeneous peer ABIs were not tested.
   
   ## Testing
   
   Baseline: `4fbd48185326ace0ea33a875099e944dc4297a77`. Tested head: 
`1d977e3a65a783b796cdcb5e07583041d8df523a`. Apps: 
`0a37af9866b7e558fe186da4de7d99cc3dda51d7`. Host: Linux x86_64, GCC 13.1.0.
   
   The temporary fixture below runs actual RPMSG exchanges between 
`sim:rpserver` and `sim:rpproxy`, backed by mock character, block and MTD 
devices. The baseline reports 46 failed checks in 88 checks. This branch 
reports zero failures in 100 checks, including 12 additional checks for 
immediate arguments, oversized requests and continued communication after 
rejection. Registration, open/close, unmount/unregister, local FIONBIO, 
geometry and MTD protection are covered. This is a paired-process integration 
fixture; it is supplied below rather than installed into the single-instance 
OSTest runner. No permanent nuttx-apps test is included.
   
   Direct API tests on 32-bit and 64-bit sim each pass 20 checks for 
variable-length arithmetic, missing headers, unsupported/nested commands, 
immediate/bool/int contracts, private ioctl lengths and audio strings. Audio is 
enabled with simulated sound disabled; RPMSG uses DEV_SIMPLE_ADDRENV. The first 
API configuration had missing sim address translation and audio backend 
dependencies and failed to link. Correcting those test options produced the 
passing results below; no production workaround was added.
   
   `qemu-armv7r:pnsh` (protected) and `qemu-armv8a:knsh` (kernel) build with 
all four clients, AUDIO and assertions enabled. The protected build reports the 
existing OSTest warning that its FPU test is only available in flat mode. 
Make/CMake `sim:nsh` builds and OSTest pass with all four clients enabled. No 
real hardware, protected/kernel runtime, SMP stress or heterogeneous-peer 
interoperability was tested. Configdata nested marshalling, MMC and legacy 
SMART operations were reviewed but not exercised at runtime.
   
   Small `sim:nsh` size comparison uses identical configurations and apps, 
optimized builds, no coverage and no test application:
   
   | Configuration | text delta | data delta | bss delta |
   |---|---:|---:|---:|
   | DEFAULT_SMALL, RPMSG disabled | +0 | +0 | +0 |
   | DEFAULT_SMALL, RPMSG clients and AUDIO enabled | +576 | +0 | +0 |
   
   The enabled comparison retains `ioctl_arglen` in the linked binary. These 
are sim measurements, not a claim about every board. Optimized size builds show 
the same existing apps/readline `savednch` warning on baseline and branch.
   
   <details>
   <summary>Testing logs before change: dual sim</summary>
   
   ```text
   G50 channel=rpmsgdev added_failures=4
   G50 channel=rpmsgfs added_failures=11
   G50 channel=rpmsgblk added_failures=15
   G50 channel=rpmsgmtd added_failures=16
   G50 RESULT checks=88 failures=46
   ```
   
   </details>
   
   <details>
   <summary>Testing logs after change: dual sim and API tests</summary>
   
   ```text
   G50 channel=rpmsgdev added_failures=0
   G50 channel=rpmsgfs added_failures=0
   G50 channel=rpmsgblk added_failures=0
   G50 channel=rpmsgmtd added_failures=0
   G50 RESULT checks=100 failures=0
   G50 API bits=32 checks=20 failures=0
   G50 API bits=64 checks=20 failures=0
   ```
   
   </details>
   
   <details>
   <summary>Build and runtime gate</summary>
   
   ```text
   target   : nuttx
   branch   : fs/ioctl-arglen
   head     : 1d977e3a65a783b796cdcb5e07583041d8df523a
   subject  : fs: centralize device ioctl argument sizing for RPMSG forwarding
   commits  : 1
   base     : 4fbd481853 (merge-base with upstream/master)
   behind   : 0 commits of upstream/master
   nuttx    : 1d977e3a65
   apps     : 0a37af9866
   options  : CONFIG_RPTUN CONFIG_DEV_SIMPLE_ADDRENV CONFIG_FS_RPMSGFS 
CONFIG_DEV_RPMSG CONFIG_BLK_RPMSG CONFIG_MTD CONFIG_RPMSGMTD 
CONFIG_DEBUG_ASSERTIONS
   host     : Linux x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0
   checkpatch: rc=0
   signer   : jingfei <[email protected]>
   commits missing your Signed-off-by: 0
   make build: rc=0
   warnings in changed files: 0
   ostest: Exiting with status 0
   cmake reconfigure: rc=0
   cmake build: rc=0
   worktree tracked changes after: 0
   RESULT: PASS
   qemu-armv7r:pnsh build PASS
   qemu-armv8a:knsh build PASS
   ```
   
   </details>
   
   <details>
   <summary>Size output: baseline, branch, RPMSG baseline, RPMSG 
branch</summary>
   
   ```text
   text    data     bss     dec     hex filename
    551285         2800   13056  567141   8a765 nuttx
   
   text    data     bss     dec     hex filename
    551285         2800   13056  567141   8a765 nuttx
   
   text    data     bss     dec     hex filename
    657098         3320   13248  673666   a4782 nuttx
   
   text    data     bss     dec     hex filename
    657674         3320   13248  674242   a49c2 nuttx
   ```
   
   </details>
   
   To reproduce the transport checks, place the following fixture in 
`apps/examples/arglencheck/` and the runner in 
`<work>/pr-ioctl-arglen/transport-test.py`, beside the `nuttx/` and `apps/` 
trees. Install `pexpect` and the normal sim build prerequisites. Run serially:
   
   ```sh
   taskset -c 0,1 python3 pr-ioctl-arglen/transport-test.py 4fbd48185326 
pr-ioctl-arglen/baseline
   taskset -c 0,1 python3 pr-ioctl-arglen/transport-test.py fs/ioctl-arglen 
pr-ioctl-arglen/branch extended
   ```
   
   The API test additionally enables EXAMPLES_ARGLENCHECK_SHARED and AUDIO and 
runs `arglencheck api`, once with SIM_M32=y and once with SIM_M32 disabled. The 
runner uses one server/proxy pair and clears its `server-proxy*` shared-memory 
files; use an isolated sim workspace.
   
   <details>
   <summary>Temporary fixture: Kconfig</summary>
   
   ```text
   config EXAMPLES_ARGLENCHECK
        tristate "RPMSG ioctl sizing validation (local)"
        default n
   
   config EXAMPLES_ARGLENCHECK_SHARED
        bool "Validate the shared ioctl sizing API"
        depends on EXAMPLES_ARGLENCHECK
        default n
   ```
   
   </details>
   
   <details>
   <summary>Temporary fixture: Make.defs</summary>
   
   ```text
   ifneq ($(CONFIG_EXAMPLES_ARGLENCHECK),)
   CONFIGURED_APPS += $(APPDIR)/examples/arglencheck
   endif
   ```
   
   </details>
   
   <details>
   <summary>Temporary fixture: Makefile</summary>
   
   ```text
   include $(APPDIR)/Make.defs
   PROGNAME = arglencheck
   PRIORITY = SCHED_PRIORITY_DEFAULT
   STACKSIZE = 8192
   MODULE = $(CONFIG_EXAMPLES_ARGLENCHECK)
   CFLAGS += -I$(TOPDIR)/fs
   MAINSRC = arglencheck_main.c
   include $(APPDIR)/Application.mk
   ```
   
   </details>
   
   <details>
   <summary>Temporary fixture: CMakeLists.txt</summary>
   
   ```text
   if(CONFIG_EXAMPLES_ARGLENCHECK)
     nuttx_add_application(NAME arglencheck SRCS arglencheck_main.c STACKSIZE 
8192
                           INCLUDE_DIRECTORIES ${NUTTX_DIR}/fs)
   endif()
   ```
   
   </details>
   
   <details>
   <summary>Temporary fixture: arglencheck_main.c</summary>
   
   ```c
   /****************************************************************************
    * apps/examples/arglencheck/arglencheck_main.c
    *
    * SPDX-License-Identifier: Apache-2.0
    *
    * 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 <nuttx/config.h>
   #include <sys/ioctl.h>
   #include <sys/mount.h>
   #include <stdbool.h>
   #include <stdint.h>
   #include <stddef.h>
   #include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
   #include <limits.h>
   #include <fcntl.h>
   #include <errno.h>
   #include <unistd.h>
   #include <termios.h>
   #include <nuttx/audio/audio.h>
   #include <nuttx/mmcsd.h>
   #include <nuttx/fs/fs.h>
   #include <nuttx/fs/ioctl.h>
   #include <nuttx/drivers/rpmsgdev.h>
   #include <nuttx/drivers/rpmsgblk.h>
   #include <nuttx/mtd/mtd.h>
   #include <nuttx/mtd/configdata.h>
   #include <nuttx/input/mouse.h>
   #include <nuttx/power/battery_ioctl.h>
   #include <nuttx/video/fb.h>
   
   /****************************************************************************
    * Private Data
    
****************************************************************************/
   
   static int g_checks;
   static int g_failures;
   
   /****************************************************************************
    * Private Functions
    
****************************************************************************/
   
   static void check(bool ok, FAR const char *what)
   {
     g_checks++;
     if (!ok)
       {
         g_failures++;
         printf("FAIL %s errno=%d\n", what, errno);
       }
   }
   
   #ifdef CONFIG_DEV_RPMSG_SERVER
   static int target_ioctl(int cmd, unsigned long arg)
   {
     FAR void *p = (FAR void *)(uintptr_t)arg;
     int value = 123;
     bool online = true;
     struct termios term;
   
     switch (cmd)
       {
         case FIONBIO:
           return 0;
         case FIONREAD:
         case FIONSPACE:
         case FBIOGET_POWER:
         case BATIOC_GET_PROTOCOL:
           memcpy(p, &value, sizeof(value));
           return 0;
         case BATIOC_ONLINE:
           memcpy(p, &online, sizeof(online));
           return 0;
         case TCGETS:
           memset(&term, 0, sizeof(term));
           term.c_iflag = 0x123;
           memcpy(p, &term, sizeof(term));
           return 0;
         case TCSETS:
           memcpy(&term, p, sizeof(term));
           return term.c_iflag == 0x456 ? 0 : -EINVAL;
         case FBIOSET_POWER:
           return arg == 7 ? 0 : -EINVAL;
         case BIOC_FLUSH:
           return 0;
         case MTDIOC_PROTECT:
         case MTDIOC_UNPROTECT:
           return 0;
         case MSIOC_VENDOR:
           {
             size_t len;
   
             memcpy(&len, p, sizeof(len));
             if (len == 4)
               {
                 memcpy((FAR char *)p +
                        offsetof(struct mouse_vendor_cmd_s, data), "pong", 4);
                 return 0;
               }
   
             return -EINVAL;
           }
   
         default:
           return -ENOTTY;
       }
   }
   
   static int char_ioctl(FAR struct file *f, int cmd, unsigned long arg)
   {
     return target_ioctl(cmd, arg);
   }
   
   static const struct file_operations g_char_ops =
   {
     .ioctl = char_ioctl
   };
   
   static int block_geometry(FAR struct inode *inode, FAR struct geometry *geo)
   {
     memset(geo, 0, sizeof(*geo));
     geo->geo_available = true;
     geo->geo_writeenabled = true;
     geo->geo_sectorsize = 32;
     geo->geo_nsectors = 16;
     return 0;
   }
   
   static int block_ioctl(FAR struct inode *inode, int cmd, unsigned long arg)
   {
     return target_ioctl(cmd, arg);
   }
   
   static ssize_t block_read(FAR struct inode *inode, FAR unsigned char *buf,
                             blkcnt_t start, unsigned int count)
   {
     memset(buf, 0, count * 32);
     return count;
   }
   
   static ssize_t block_write(FAR struct inode *inode,
                              FAR const unsigned char *buf,
                              blkcnt_t start, unsigned int count)
   {
     return count;
   }
   
   static const struct block_operations g_block_ops =
   {
     .read = block_read,
     .write = block_write,
     .geometry = block_geometry,
     .ioctl = block_ioctl
   };
   
   static int mtd_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
   {
     if (cmd == MTDIOC_GEOMETRY)
       {
         struct mtd_geometry_s geo;
   
         memset(&geo, 0, sizeof(geo));
         geo.blocksize = 32;
         geo.erasesize = 128;
         geo.neraseblocks = 4;
         memcpy((FAR void *)(uintptr_t)arg, &geo, sizeof(geo));
         return 0;
       }
   
     return target_ioctl(cmd, arg);
   }
   
   static struct mtd_dev_s g_mtd =
   {
     .ioctl = mtd_ioctl
   };
   
   static int serve(void)
   {
     check(register_driver("/dev/g50c", &g_char_ops, 0666, NULL) == 0,
           "register char");
     check(register_blockdriver("/dev/g50b", &g_block_ops, 0666, NULL) == 0,
           "register block");
     check(register_mtddriver("/dev/g50m", &g_mtd, 0666, NULL) == 0,
           "register mtd");
     check(rpmsgdev_export("proxy", "/dev/g50c") == 0, "export char");
     printf("G50 READY checks=%d failures=%d\n", g_checks, g_failures);
     return g_failures != 0;
   }
   #endif
   
   #ifdef CONFIG_DEV_RPMSG
   struct channel_s
   {
     int fd;
     FAR struct inode *block;
     FAR struct mtd_dev_s *mtd;
   };
   
   static int transfer(FAR struct channel_s *ch, int cmd, unsigned long arg)
   {
     int ret;
   
     if (ch->block != NULL)
       {
         return ch->block->u.i_bops->ioctl(ch->block, cmd, arg);
       }
   
     if (ch->mtd != NULL)
       {
         return ch->mtd->ioctl(ch->mtd, cmd, arg);
       }
   
     ret = ioctl(ch->fd, cmd, arg);
     return ret < 0 ? -errno : ret;
   }
   
   static void exercise(FAR const char *name, FAR struct channel_s *ch,
                        bool extended)
   {
     int before = g_failures;
     int value;
     int ret;
     int commands[] =
     {
       FIONREAD, FIONSPACE, FBIOGET_POWER, BATIOC_GET_PROTOCOL
     };
   
     size_t i;
     struct termios term;
     union
     {
       struct mouse_vendor_cmd_s mouse;
       unsigned char data[sizeof(struct mouse_vendor_cmd_s) + 4];
     } vendor;
   
     for (i = 0; i < sizeof(commands) / sizeof(commands[0]); i++)
       {
         /* Reserve the legacy largest size during baseline comparison. */
   
         union
         {
           int integer;
           unsigned char pad[sizeof(struct batio_operate_msg_s)];
         } result;
   
         memset(&result, 0, sizeof(result));
         ret = transfer(ch, commands[i], (unsigned long)(uintptr_t)&result);
         check(ret == 0, "integer command status");
         check(result.integer == 123, "integer command copyout");
       }
   
     memset(&term, 0, sizeof(term));
     check(transfer(ch, TCGETS, (unsigned long)(uintptr_t)&term) == 0,
           "termios get status");
     check(term.c_iflag == 0x123, "termios get contents");
     term.c_iflag = 0x456;
     check(transfer(ch, TCSETS, (unsigned long)(uintptr_t)&term) == 0,
           "termios set contents");
   
     memset(&vendor, 0, sizeof(vendor));
     vendor.mouse.len = 4;
     memcpy(vendor.mouse.data, "ping", 4);
     check(transfer(ch, MSIOC_VENDOR,
                    (unsigned long)(uintptr_t)&vendor) == 0, "vendor status");
     check(memcmp(vendor.mouse.data, "pong", 4) == 0, "vendor copyout");
     check(transfer(ch, BIOC_FLUSH, 0) == 0, "no-buffer command");
     check(transfer(ch, _DIOC(253), 0) == -ENOTTY, "unknown command");
   
     value = 0;
     check(transfer(ch, BATIOC_ONLINE,
                    (unsigned long)(uintptr_t)&value) == 0, "bool status");
     check(*(FAR bool *)&value, "bool value");
   
     if (extended)
       {
         check(transfer(ch, FBIOSET_POWER, 7) == 0, "immediate power");
         vendor.mouse.len = 4096;
         check(transfer(ch, MSIOC_VENDOR,
                        (unsigned long)(uintptr_t)&vendor) == -EMSGSIZE,
               "oversized payload rejected");
         vendor.mouse.len = 4;
         check(transfer(ch, MSIOC_VENDOR,
                        (unsigned long)(uintptr_t)&vendor) == 0,
               "transport usable after rejection");
       }
   
     printf("G50 channel=%s added_failures=%d\n", name, g_failures - before);
   }
   
   static int proxy(bool extended)
   {
     struct channel_s ch =
     {
       .fd = -1
     };
   
     FAR struct inode *mtdnode = NULL;
     struct geometry geo;
     int nonblock = 1;
     int ret;
   
     check(rpmsgdev_register("server", "/dev/g50c", "/dev/g50proxy") == 0,
           "rpmsgdev register");
     ch.fd = open("/dev/g50proxy", O_RDWR);
     check(ch.fd >= 0, "rpmsgdev open");
     if (ch.fd >= 0)
       {
         check(ioctl(ch.fd, FIONBIO, (unsigned long)(uintptr_t)&nonblock) == 0,
               "rpmsgdev local FIONBIO");
         exercise("rpmsgdev", &ch, extended);
         check(close(ch.fd) == 0, "rpmsgdev close");
       }
   
     check(mount(NULL, "/g50fs", "rpmsgfs", 0, "cpu=server,fs=/dev") == 0,
           "rpmsgfs mount");
     ch.fd = open("/g50fs/g50c", O_RDWR);
     check(ch.fd >= 0, "rpmsgfs open");
     if (ch.fd >= 0)
       {
         exercise("rpmsgfs", &ch, extended);
         check(close(ch.fd) == 0, "rpmsgfs close");
       }
   
     check(umount("/g50fs") == 0, "rpmsgfs unmount");
     check(rpmsgblk_register("server", "/dev/g50b", "/dev/g50block") == 0,
           "rpmsgblk register");
     ret = open_blockdriver("/dev/g50block", 0, &ch.block);
     check(ret == 0, "rpmsgblk open");
     if (ret == 0)
       {
         check(ch.block->u.i_bops->geometry(ch.block, &geo) == 0 &&
               geo.geo_sectorsize == 32, "rpmsgblk dedicated geometry");
         exercise("rpmsgblk", &ch, extended);
         check(close_blockdriver(ch.block) == 0, "rpmsgblk close");
         ch.block = NULL;
       }
   
     check(rpmsgmtd_register("server", "/dev/g50m", "/dev/g50mtd") == 0,
           "rpmsgmtd register");
     ret = find_mtddriver("/dev/g50mtd", &mtdnode);
     check(ret == 0, "rpmsgmtd open");
     if (ret == 0)
       {
         struct mtd_geometry_s mgeo;
         struct mtd_protect_s protect;
   
         ch.mtd = mtdnode->u.i_mtd;
         memset(&protect, 0, sizeof(protect));
         check(transfer(&ch, MTDIOC_GEOMETRY,
                        (unsigned long)(uintptr_t)&mgeo) == 0 &&
               mgeo.blocksize == 32, "rpmsgmtd dedicated geometry");
         check(transfer(&ch, MTDIOC_PROTECT,
                        (unsigned long)(uintptr_t)&protect) == 0,
               "rpmsgmtd existing protect");
         exercise("rpmsgmtd", &ch, extended);
         check(close_mtddriver(mtdnode) == 0, "rpmsgmtd close");
       }
   
     check(rpmsgmtd_unregister("/dev/g50mtd") == 0, "rpmsgmtd unregister");
     check(rpmsgblk_unregister("/dev/g50block") == 0, "rpmsgblk unregister");
     check(rpmsgdev_unregister("/dev/g50proxy") == 0, "rpmsgdev unregister");
     printf("G50 RESULT checks=%d failures=%d\n", g_checks, g_failures);
     return g_failures != 0;
   }
   #endif
   
   #ifdef CONFIG_EXAMPLES_ARGLENCHECK_SHARED
   static int boundary(void)
   {
     struct mouse_vendor_cmd_s mouse;
     unsigned long arg = (unsigned long)(uintptr_t)&mouse;
     char text[] = "key=value";
   
     check(ioctl_arglen(MSIOC_VENDOR, 0) == -EINVAL, "missing mouse header");
     mouse.len = 0;
     check(ioctl_arglen(MSIOC_VENDOR, arg) == sizeof(mouse), "empty payload");
     mouse.len = SSIZE_MAX - sizeof(mouse);
     check(ioctl_arglen(MSIOC_VENDOR, arg) == SSIZE_MAX, "last valid size");
     mouse.len++;
     check(ioctl_arglen(MSIOC_VENDOR, arg) == -EOVERFLOW, "size overflow");
     mouse.len = SIZE_MAX;
     check(ioctl_arglen(MSIOC_VENDOR, arg) == -EOVERFLOW, "max size_t");
     check(ioctl_arglen(CFGDIOC_GETCONFIG, 0) == -ENOTTY, "nested configdata");
     check(ioctl_arglen(MMC_IOC_CMD, 0) == -ENOTTY, "nested MMC");
     check(ioctl_arglen(BIOC_GETFORMAT, 0) == -ENOTTY, "legacy SMART local");
     check(ioctl_arglen(_DIOC(253), 0) == -ENOTTY, "unknown command size");
     check(ioctl_arglen(FBIOSET_POWER, 7) == 0, "immediate argument size");
     check(ioctl_arglen(BATIOC_ONLINE, 0) == sizeof(bool), "bool contract");
     check(ioctl_arglen(BATIOC_GET_PROTOCOL, 0) == sizeof(int), "int contract");
   #ifdef CONFIG_DEV_RPMSG
     {
       struct rpmsgdev_private_ioctl req;
       ssize_t expected;
   
       check(ioctl_arglen(RPMSGDEV_PRIVATE_IOCTL, 0) == -EINVAL,
             "missing private header");
       req.len = UINT32_MAX;
       expected = (uint64_t)UINT32_MAX > (uint64_t)SSIZE_MAX - sizeof(req) ?
                  -EOVERFLOW : (ssize_t)((uint64_t)UINT32_MAX + sizeof(req));
       check(ioctl_arglen(RPMSGDEV_PRIVATE_IOCTL,
                          (unsigned long)(uintptr_t)&req) == expected,
             "private length limit");
     }
   
   #endif
   #ifdef CONFIG_AUDIO
     check(ioctl_arglen(AUDIOIOC_SETPARAMTER, 0) == -EINVAL,
           "missing audio string");
     check(ioctl_arglen(AUDIOIOC_SETPARAMTER,
                        (unsigned long)(uintptr_t)text) == sizeof(text),
           "audio terminated string");
     text[0] = '\0';
     check(ioctl_arglen(AUDIOIOC_SETPARAMTER,
                        (unsigned long)(uintptr_t)text) == 1,
           "empty audio string");
     check(ioctl_arglen(AUDIOIOC_GETBUFFERINFO, 0) ==
           sizeof(struct ap_buffer_info_s), "audio buffer information");
     check(ioctl_arglen(AUDIOIOC_GETAUDIOINFO, 0) ==
           sizeof(struct audio_info_s),
           "audio stream information");
     check(ioctl_arglen(AUDIOIOC_HWRESET, 0) == 0, "audio no-buffer command");
   #endif
     printf("G50 API bits=%u checks=%d failures=%d\n",
            (unsigned int)(sizeof(size_t) * CHAR_BIT), g_checks, g_failures);
     return g_failures != 0;
   }
   #endif
   
   /****************************************************************************
    * Public Functions
    
****************************************************************************/
   
   int main(int argc, FAR char **argv)
   {
   #ifdef CONFIG_EXAMPLES_ARGLENCHECK_SHARED
     if (argc > 1 && strcmp(argv[1], "api") == 0)
       {
         return boundary();
       }
   
   #endif
   #ifdef CONFIG_DEV_RPMSG_SERVER
     return serve();
   #elif defined(CONFIG_DEV_RPMSG)
     return proxy(argc > 1 && strcmp(argv[1], "extended") == 0);
   #else
     return 1;
   #endif
   }
   ```
   
   </details>
   
   <details>
   <summary>Dual-sim runner</summary>
   
   ```python
   import os, pathlib, subprocess, sys, time
   import pexpect
   root=pathlib.Path(__file__).resolve().parent.parent
   nx=root/'nuttx'; apps=root/'apps'
   rev=sys.argv[1]; out=pathlib.Path(sys.argv[2]).resolve(); 
extended=len(sys.argv)>3 and sys.argv[3]=='extended'
   out.mkdir(parents=True,exist_ok=True)
   
orig=subprocess.check_output(['git','branch','--show-current'],cwd=nx,text=True).strip()
   assert orig
   assert not 
subprocess.check_output(['git','status','--porcelain','--untracked-files=no'],cwd=nx,text=True).strip()
   procs=[]
   def run(args,log,check=True):
    with (out/log).open('w') as f:
     r=subprocess.run(args,cwd=nx,stdout=f,stderr=subprocess.STDOUT)
    if check and r.returncode: raise RuntimeError(f'{log}: rc={r.returncode}')
    return r.returncode
   try:
    subprocess.run(['git','switch','--detach',rev],cwd=nx,check=True)
    
(out/'revision.txt').write_text(subprocess.check_output(['git','rev-parse','HEAD'],cwd=nx,text=True))
    
(out/'apps-revision.txt').write_text(subprocess.check_output(['git','rev-parse','HEAD'],cwd=apps,text=True))
    for board in ['rpserver','rpproxy']:
     run(['make','distclean'],board+'-clean.log',False)
     
run(['git','clean','-fdXq','openamp/libmetal','openamp/open-amp'],board+'-generated-clean.log')
     
run(['./tools/configure.sh','-l','-a',os.path.relpath(apps,nx),'sim:'+board],board+'-configure.log')
     opts=['EXAMPLES_ARGLENCHECK','MTD','FS_TMPFS','DEBUG_ASSERTIONS']
     for key in opts:
      
subprocess.run(['kconfig-tweak','--file','.config','--enable','CONFIG_'+key],cwd=nx,check=True)
     for key in ['SIM_NETDEV','SYSLOG_RPMSG']:
      
subprocess.run(['kconfig-tweak','--file','.config','--disable','CONFIG_'+key],cwd=nx,check=True)
     run(['make','olddefconfig'],board+'-olddefconfig.log')
     
config=(nx/'.config').read_text();(out/(board+'.config')).write_text(config)
     for key in opts: assert 'CONFIG_'+key+'=y\n' in config,key
     print('BUILD',board,flush=True)
     run(['make','-j2'],board+'-make.log')
     (out/board).write_bytes((nx/'nuttx').read_bytes());(out/board).chmod(0o755)
     symbols=subprocess.check_output(['nm',str(out/board)],text=True)
     assert 'arglencheck_main' in symbols, 'test app missing from binary'
     print('BUILT',board,flush=True)
    for p in pathlib.Path('/dev/shm').glob('server-proxy*'):
     p.unlink()
    
server=pexpect.spawn(str(out/'rpserver'),cwd=str(nx),encoding='utf-8',codec_errors='replace',timeout=45)
    procs.append(server); server.logfile=(out/'server.log').open('w')
    server.expect(r'server> ')
    server.sendline('arglencheck')
    server.expect(r'G50 READY checks=4 failures=0')
    server.expect(r'server> ')
    
proxy=pexpect.spawn(str(out/'rpproxy'),cwd=str(nx),encoding='utf-8',codec_errors='replace',timeout=45)
    procs.append(proxy); proxy.logfile=(out/'run.log').open('w')
    proxy.expect(r'proxy> ')
    proxy.sendline('arglencheck'+(' extended' if extended else ''))
    proxy.expect(r'G50 RESULT checks=(\d+) failures=(\d+)',timeout=120)
    checks=int(proxy.match.group(1));fails=int(proxy.match.group(2))
    (out/'result.txt').write_text(f'checks={checks} failures={fails}\n')
    print('RESULT',checks,fails,flush=True)
    proxy.expect(r'proxy> ')
    proxy.sendline('poweroff');proxy.expect(pexpect.EOF,timeout=15)
    server.sendline('poweroff');server.expect(pexpect.EOF,timeout=15)
   finally:
    for p in procs:
     if p.isalive(): p.terminate(force=True)
     if p.logfile: p.logfile.close()
    run(['make','distclean'],'final-clean.log',False)
    subprocess.run(['git','switch',orig],cwd=nx,check=True)
   ```
   
   </details>
   
   ## PR verification Self-Check
   
   - [x] This PR introduces only one functional change.
   - [x] I have updated all required description fields above.
   - [x] Commit format, coding style and documentation have been checked.
   - [ ] My PR is still work in progress (not ready for review).
   - [x] My PR is ready for review; validation limits are listed above.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to