Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add renode-cli #28944

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions recipes/renode-cli/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env bash

set -o xtrace -o nounset -o pipefail -o errexit

mkdir -p ${PREFIX}/bin
mkdir -p ${PREFIX}/libexec/${PKG_NAME}
export PATH="${DOTNET_ROOT}/dotnet:${PATH}"

install_prefix="${PREFIX}/opt/${PKG_NAME}"

dotnet_version=$(dotnet --version)
framework_version=${dotnet_version%.*}

# Patch the project files to use the correct .NET version
find lib src tests -name "*.csproj" -exec sed -i -E \
-e "s/([>;])net6.0([<;])/\1net${framework_version}\2/" \
-e "s|^((\s+)<PropertyGroup>)|\1\n\2\2<NoWarn>CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051</NoWarn>|" \
-e 's|^(\s+)<(Package)?Reference\s+Include="Mono.Posix".*\n||g' \
{} \;
find . -type d -name "obj" -exec rm -rf {} +
find . -type d -name "bin" -exec rm -rf {} +
sed -i -E 's/(ReleaseHeadless\|Any .+ = )Debug/\1Release/' Renode_NET.sln

# Prevent CMake build since we provide the binaries
mkdir -p ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/bin/Release/lib
cp ${BUILD_PREFIX}/lib/renode-cores/* ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/bin/Release/lib

# Remove the C cores that are not built in this recipe
rm -f ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/translate*.cproj

# Add dynamic libraries framewkr
cp ${RECIPE_DIR}/helpers/DynamicLibraryLoader.{cs,csproj} ${SRC_DIR}/src/Renode

chmod +x tools/{building,packaging}/*.sh
${RECIPE_DIR}/helpers/renode_build_with_dotnet.sh ${framework_version}

# Install procedure
mkdir -p $PREFIX/libexec/${PKG_NAME}
cp -r output/bin/Release/net${framework_version}/* $PREFIX/libexec/${PKG_NAME}/

mkdir -p $PREFIX/opt/${PKG_NAME}/scripts
mkdir -p $PREFIX/opt/${PKG_NAME}/platforms
mkdir -p $PREFIX/opt/${PKG_NAME}/tests
mkdir -p $PREFIX/opt/${PKG_NAME}/tools
mkdir -p $PREFIX/opt/${PKG_NAME}/licenses

cp .renode-root $PREFIX/opt/${PKG_NAME}/
cp -r scripts/* $PREFIX/opt/${PKG_NAME}/scripts/
cp -r platforms/* $PREFIX/opt/${PKG_NAME}/platforms/
cp -r tests/* $PREFIX/opt/${PKG_NAME}/tests/
cp -r tools/metrics_analyzer $PREFIX/opt/${PKG_NAME}/tools
cp -r tools/execution_tracer $PREFIX/opt/${PKG_NAME}/tools
cp -r tools/gdb_compare $PREFIX/opt/${PKG_NAME}/tools
cp -r tools/sel4_extensions $PREFIX/opt/${PKG_NAME}/tools

cp lib/resources/styles/robot.css $PREFIX/opt/${PKG_NAME}/tests

tools/packaging/common_copy_licenses.sh $PREFIX/opt/${PKG_NAME}/licenses linux
cp -r $PREFIX/opt/${PKG_NAME}/licenses license-files

sed -i.bak "s#os\.path\.join(this_path, '\.\./lib/resources/styles/robot\.css')#os.path.join(this_path,'robot.css')#g" $PREFIX/opt/${PKG_NAME}/tests/robot_tests_provider.py
rm $PREFIX/opt/${PKG_NAME}/tests/robot_tests_provider.py.bak

mkdir -p $PREFIX/bin/
cat > $PREFIX/bin/renode <<"EOF"
#!/bin/sh
exec "${DOTNET_ROOT}"/dotnet exec "${CONDA_PREFIX}"/libexec/renode-cli/Renode.dll "$@"
EOF
chmod +x ${PREFIX}/bin/renode

cat > $PREFIX/bin/renode.cmd <<"EOF"
call %DOTNET_ROOT%\dotnet exec %CONDA_PREFIX%\libexec\libexec\renode-cli\Renode.dll %*
EOF
chmod +x ${PREFIX}/bin/renode

cat > $PREFIX/bin/renode-test <<"EOF"
#!/usr/bin/env bash

STTY_CONFIG=`stty -g 2>/dev/null`
python3 "${CONDA_PREFIX}"/opt/renode-cli/tests/run_tests.py --robot-framework-remote-server-full-directory "${CONDA_PREFIX}"/libexec/renode-cli "$@"
RESULT_CODE=$?
if [ -n "${STTY_CONFIG:-}" ]
then
stty "$STTY_CONFIG"
fi
exit $RESULT_CODE
EOF
chmod +x ${PREFIX}/bin/renode-test
90 changes: 90 additions & 0 deletions recipes/renode-cli/helpers/DynamicLibraryLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Runtime.InteropServices;

public class DynamicLibraryLoader
{
private IntPtr _libraryHandle;
private readonly string _libraryPath;

public DynamicLibraryLoader(string libraryPath)
{
_libraryPath = libraryPath;
#if PLATFORM_WINDOWS
_libraryHandle = LoadLibrary(libraryPath);
#elif PLATFORM_LINUX || PLATFORM_OSX
_libraryHandle = dlopen(libraryPath, RTLD_NOW);
#endif

if (_libraryHandle == IntPtr.Zero)
{
throw new Exception("Failed to load library: " + libraryPath);
}
}

public void LoadLibrary(string libraryName)
{
var fullPath = System.IO.Path.Combine(_libraryPath, libraryName);
#if PLATFORM_WINDOWS
_libraryHandle = LoadLibrary(fullPath);
#elif PLATFORM_LINUX || PLATFORM_OSX
_libraryHandle = dlopen(fullPath, RTLD_NOW);
#endif

if (_libraryHandle == IntPtr.Zero)
{
throw new Exception("Failed to load library: " + fullPath);
}
}

public T GetFunctionDelegate<T>(string functionName) where T : Delegate
{
IntPtr functionAddress = IntPtr.Zero;

#if PLATFORM_WINDOWS
functionAddress = GetProcAddress(_libraryHandle, functionName);
#elif PLATFORM_LINUX || PLATFORM_OSX
functionAddress = dlsym(_libraryHandle, functionName);
#endif

if (functionAddress == IntPtr.Zero)
{
throw new Exception("Failed to get function address: " + functionName);
}

return Marshal.GetDelegateForFunctionPointer<T>(functionAddress);
}

~DynamicLibraryLoader()
{
if (_libraryHandle != IntPtr.Zero)
{
#if PLATFORM_WINDOWS
FreeLibrary(_libraryHandle);
#elif PLATFORM_LINUX || PLATFORM_OSX
dlclose(_libraryHandle);
#endif
}
}

#if PLATFORM_WINDOWS
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr LoadLibrary(string dllToLoad);

[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool FreeLibrary(IntPtr hModule);
#elif PLATFORM_LINUX || PLATFORM_OSX
[DllImport("libdl.so")]
private static extern IntPtr dlopen(string fileName, int flags);

[DllImport("libdl.so")]
private static extern IntPtr dlsym(IntPtr handle, string symbol);

[DllImport("libdl.so")]
private static extern int dlclose(IntPtr handle);

private const int RTLD_NOW = 2;
#endif
}
19 changes: 19 additions & 0 deletions recipes/renode-cli/helpers/DynamicLibraryLoader.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>7.3</LangVersion>
<DefineConstants>$(DefineConstants);PLATFORM_LINUX</DefineConstants>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<DefineConstants>$(DefineConstants);PLATFORM_WINDOWS</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(OS)' == 'OSX'">
<DefineConstants>$(DefineConstants);PLATFORM_OSX</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Include="DynamicLibraryLoader.cs" />
</ItemGroup>
</Project>
101 changes: 101 additions & 0 deletions recipes/renode-cli/helpers/renode_build_with_dotnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash

set -uex

framework_version=$1
shift 1

OUTPUT_DIRECTORY="${SRC_DIR}/output"

CONFIGURATION="Release"
BUILD_PLATFORM="Any CPU"
HEADLESS=true
NET=true
TFM="net${framework_version}"
GENERATE_DOTNET_BUILD_TARGET=true
NET_FRAMEWORK_VER=
RID="linux-x64"
HOST_ARCH="i386"
# Common cmake flags
CMAKE_COMMON=""

PARAMS=(
# By default use CC as Compiler- and LinkerPath, and AR as ArPath
${CC:+"p:CompilerPath=$CC"}
${CC:+"p:LinkerPath=$CC"}
${AR:+"p:ArPath=$AR"}
# But allow users to override it
"$@"
)

if $HEADLESS
then
BUILD_TARGET=Headless
PARAMS+=(p:GUI_DISABLED=true)
else
BUILD_TARGET=Mono
fi

cat <<EOF > "${SRC_DIR}/Directory.Build.targets"
<Project>
<PropertyGroup>
<TargetFrameworks>$TFM</TargetFrameworks>
${OS_SPECIFIC_TARGET_OPTS:+${OS_SPECIFIC_TARGET_OPTS}}
</PropertyGroup>
</Project>
EOF

export DOTNET_CLI_TELEMETRY_OPTOUT=1
CS_COMPILER="dotnet build"
TARGET="${SRC_DIR}/Renode_NET.sln"
BUILD_TYPE="dotnet"

OUT_BIN_DIR="${SRC_DIR}/output/bin/${CONFIGURATION}"
BUILD_TYPE_FILE="${OUT_BIN_DIR}/build_type"

# Copy properties file according to the running OS
mkdir -p "$OUTPUT_DIRECTORY"
rm -f "$OUTPUT_DIRECTORY/properties.csproj"
if [[ "${target_platform}" == "osx-"* ]]; then
PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/osx-properties.csproj"
elif [[ "${target_platform}" == "linux-"* ]] || [[ "${target_platform}" == "noarch" ]]; then
PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/linux-properties.csproj"
else
PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/windows-properties.csproj"
fi
cp "$PROP_FILE" "$OUTPUT_DIRECTORY/properties.csproj"

CORES_PATH="${SRC_DIR}/src/Infrastructure/src/Emulator/Cores"

PARAMS+=(p:Configuration=${CONFIGURATION}${BUILD_TARGET} p:GenerateFullPaths=true p:Platform="\"$BUILD_PLATFORM\"")

# build
function build_args_helper() {
local retStr=""
for p in "$@" ; do
if [ "$CS_COMPILER" = 'xbuild' ] ; then
retStr="${retStr} /$p"
else
retStr="${retStr} -$p"
fi
done
echo ${retStr}
}

eval "$CS_COMPILER $(build_args_helper "${PARAMS[@]}") $TARGET"
echo -n "$BUILD_TYPE" > "$BUILD_TYPE_FILE"

# copy llvm library
LLVM_LIB="libllvm-disas"
if [[ $HOST_ARCH == "aarch64" ]]; then
# aarch64 host binaries have a different name
LLVM_LIB="libllvm-disas-aarch64"
fi
if [[ "${target_platform}" == "linux-"* ]] || [[ "${target_platform}" == "noarch" ]]; then
LIB_EXT="so"
elif [[ "${target_platform}" == "osx-"* ]]; then
LIB_EXT="dylib"
else
LIB_EXT="dll"
fi
cp lib/resources/llvm/$LLVM_LIB.$LIB_EXT $OUT_BIN_DIR/libllvm-disas.$LIB_EXT
67 changes: 67 additions & 0 deletions recipes/renode-cli/patches/resolve-posix-unix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
--- a/src/Plugins/VerilatorPlugin/Connection/SocketVerilatorConnection.cs
+++ b/src/Plugins/VerilatorPlugin/Connection/SocketVerilatorConnection.cs
@@ -7,4 +7,6 @@
using System;
+using System.IO;
using System.Net;
using System.Net.Sockets;
+using System.Security.AccessControl;
using System.Text;
@@ -19,2 +21,3 @@
using Antmicro.Renode.Peripherals;
+using Antmicro.Renode.Peripherals.Bus;
using Antmicro.Renode.Peripherals.CPU;
@@ -212,3 +215,7 @@
#if !PLATFORM_WINDOWS
- Mono.Unix.Native.Syscall.chmod(value, FilePermissions.S_IRWXU); //setting permissions to 0x700
+ // Use built-in .NET methods for file permissions
+ var fileInfo = new FileInfo(value);
+ var fileSecurity = fileInfo.GetAccessControl();
+ fileSecurity.AddAccessRule(new FileSystemAccessRule(Environment.UserName, FileSystemRights.FullControl, AccessControlType.Allow));
+ fileInfo.SetAccessControl(fileSecurity);
#endif
--- a/src/Renode/Backends/Terminals/UartPtyTerminal.cs 2024-09-17 03:09:19.000000000 -0500
+++ b/src/Renode/Backends/Terminals/UartPtyTerminal.cs 2025-01-25 21:32:28.901091634 -0600
@@ -10,2 +10,3 @@
using System;
+using System.IO;
using Antmicro.Renode.Peripherals.UART;
@@ -14,4 +15,2 @@
using Antmicro.Migrant;
-using Mono.Unix;
-using System.IO;
#endif
@@ -49,3 +48,3 @@
{
- symlink.Delete();
+ File.Delete(linkName);
}
@@ -53,3 +52,3 @@
{
- throw new RecoverableException(string.Format("There was an error when removing symlink `{0}': {1}", symlink.FullName, e.Message));
+ throw new RecoverableException(string.Format("There was an error when removing symlink `{0}': {1}", symlink, e.Message));
}
@@ -105,4 +104,4 @@
{
- var slavePtyFile = new UnixFileInfo(ptyStream.SlaveName);
- symlink = slavePtyFile.CreateSymbolicLink(linkName);
+ symlink = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
+ File.CreateSymbolicLink(symlink, ptyStream.SlaveName);
}
@@ -114,4 +113,2 @@

- private UnixSymbolicLinkInfo symlink;
-
private readonly bool forceCreate;
@@ -122,2 +119,4 @@
private IOProvider io;
+ [Transient]
+ private string symlink;
}
--- a/src/Renode/Program.cs 2024-09-17 03:09:19.000000000 -0500
+++ b/src/Renode/Program.cs 2025-01-26 11:07:01.717709447 -0600
@@ -98,3 +98,3 @@
ConfigurationManager.Instance.Get("general", "terminal", "Termsharp");
- ConsoleBackend.Instance.ReportRepeatingLines = !ConfigurationManager.Instance.Get("general", "collapse-repeated-log-entries", true);
+ // Logger.LogEntriesLimit = ConfigurationManager.Instance.Get("general", "log-entries-limit", 10000);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--- a/src/Renode/Renode_NET.csproj
+++ b/src/Renode/Renode_NET.csproj
@@ -29 +29 @@
- <PackageReference Include="IronPython.StdLib" Version="2.7.11" />
+ <PackageReference Include="IronPython.StdLib" Version="2.7.12" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- a/src/Infrastructure/src/Emulator/Main/Tests/UnitTests/UnitTests_NET.csproj
+++ b/src/Infrastructure/src/Emulator/Main/Tests/UnitTests/UnitTests_NET.csproj
@@ -18,5 +18,4 @@
<PackageReference Include="Moq" Version="4.18.1" />
- <Reference Include="IronPython">
- <HintPath>..\..\..\..\..\..\..\lib\resources\libraries\IronPython.dll</HintPath>
- </Reference>
+ <PackageReference Include="IronPython" Version="2.7.12" />
+ <PackageReference Include="IronPython.StdLib" Version="2.7.12" />
<PackageReference Include="NUnit" Version="3.13.1" />
--- a/src/Infrastructure/src/Emulator/Peripherals/Peripherals/Sensors/PAC1934.cs
+++ b/src/Infrastructure/src/Emulator/Peripherals/Peripherals/Sensors/PAC1934.cs
@@ -131,1 +131,1 @@
- return BitConverter.GetBytes(registers.Read(offset));
+ return BitConverter.GetBytes((short)registers.Read(offset));
Loading
Loading