Skip to content

Commit

Permalink
attempt to fix big and keep working with little endiand
Browse files Browse the repository at this point in the history
  • Loading branch information
aodinokov committed Aug 17, 2024
1 parent 31e4f3e commit f928b9e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 125 deletions.
135 changes: 63 additions & 72 deletions .github/workflows/buildAndTest.yaml
Original file line number Diff line number Diff line change
@@ -1,55 +1,6 @@
on: [push, pull_request]
name: BuildAndTest
jobs:
big_endian_job:
# taken from https://github.com/marketplace/actions/run-on-architecture
# s390x is big endian with Ubuntu_latest which
# also has go-lang for linux: https://go.dev/dl/
# https://go.dev/dl/go1.23.0.linux-s390x.tar.gz
# The host should always be Linux.
runs-on: ubuntu-22.04
name: Build on ubuntu_latest
steps:
- uses: actions/checkout@v4
- name: Downloadin Go
run: curl -fsSL -o go.tar.gz https://go.dev/dl/go1.22.0.linux-s390x.tar.gz
- uses: uraimo/run-on-arch-action@v2
name: Run commands
id: runcmd
with:
arch: s390x
distro: ubuntu_latest

# Not required, but speeds up builds by storing container images in
# a GitHub package registry.
githubToken: ${{ github.token }}

# Set an output parameter `uname` for use in subsequent steps
run: |
set -x
uname -a
apt update && apt-get install -y ca-certificates pkg-config make gcc check
tar -C /usr/local -xzf go.tar.gz && rm go.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
export GO111MODULE=on
go test -cover ./...
go build
make $(pwd)/src/value_bitfields_test && ./src/value_bitfields_test || true
# cat src/value_bitfields_test.reflect.c
# make test all || true #cat src/value_base_type_test.reflect.c
# this doesn't work (line 4: GITHUB_OUTPUT: unbound variable) echo uname::test >> $GITHUB_OUTPUT
echo ::set-output name=uname::$(uname -a)
- name: Get the output
# Echo the `uname` output parameter from the `runcmd` step
run: |
echo "The uname output was ${{ steps.runcmd.outputs.uname }}"
# ubuntu:
# runs-on: ubuntu-latest
# strategy:
Expand All @@ -76,28 +27,28 @@ jobs:
# - name: Examples test
# run: make test all DWARF_VER_FORCE=${{matrix.dwarf-version}}

# macos:
# runs-on: macos-latest
# strategy:
# matrix:
# go-version: [1.22.x] # , 1.21.x, 1.20.x]
# steps:
# - name: Install Go
# uses: actions/setup-go@v3
# with:
# go-version: ${{ matrix.go-version }}
# - name: prerequisites # macos speicific
# run: brew install pkg-config check
# - name: Checkout code
# uses: actions/checkout@v3
# - name: Test
# env:
# GO111MODULE: on
# run: go test -cover ./...
# - name: Build
# run: go build
# - name: Examples test
# run: make test all
macos:
runs-on: macos-latest
strategy:
matrix:
go-version: [1.22.x] # , 1.21.x, 1.20.x]
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: prerequisites # macos speicific
run: brew install pkg-config check
- name: Checkout code
uses: actions/checkout@v3
- name: Test
env:
GO111MODULE: on
run: go test -cover ./...
- name: Build
run: go build
- name: Examples test
run: make test all

# windows:
# runs-on: windows-latest
Expand Down Expand Up @@ -129,4 +80,44 @@ jobs:
# - name: Build
# run: go build
# - name: Examples test
# run: make test all
# run: make test all

big_endian_job:
# taken from https://github.com/marketplace/actions/run-on-architecture
# s390x is big endian with Ubuntu_latest which
# also has go-lang for linux: https://go.dev/dl/
# https://go.dev/dl/go1.23.0.linux-s390x.tar.gz
# GO_TELEMETRY_CHILD=off
# The host should always be Linux.
runs-on: ubuntu-22.04
name: ubuntu (s390x - big endian)
steps:
- uses: actions/checkout@v4
- name: Downloadin Go
run: curl -fsSL -o go.tar.gz https://go.dev/dl/go1.22.0.linux-s390x.tar.gz
- uses: uraimo/run-on-arch-action@v2
name: Run commands
id: runcmd
with:
arch: s390x
distro: ubuntu_latest

# Not required, but speeds up builds by storing container images in
# a GitHub package registry.
githubToken: ${{ github.token }}

# Set an output parameter `uname` for use in subsequent steps
run: |
set -x
uname -a
apt update && apt-get install -y ca-certificates pkg-config make gcc g++ check # todo: libffi-dev
tar -C /usr/local -xzf go.tar.gz && rm go.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
export GO111MODULE=on
go test -cover ./...
go build
make test all
4 changes: 0 additions & 4 deletions src/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,6 @@ int metac_entry_member_bitfield_offsets(metac_entry_t *p_memb_entry,
metac_offset_t _data_bit_offset = *p_memb_entry->member_info.p_data_bit_offset;
*p_bit_size = p_memb_entry->member_info.p_bit_size != NULL?(*p_memb_entry->member_info.p_bit_size): 0;

// printf("fld %4s, data_bit_offset %d, bit_size %d\n",
// p_memb_entry->name, (int)(_data_bit_offset), (int)*p_bit_size);


// out

*p_byte_offset = _data_bit_offset >> 3;
Expand Down
8 changes: 2 additions & 6 deletions src/value.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,9 @@ static int _entry_bitfield_read(metac_entry_t *p_memb_entry, void * base_addr, v
// assert(parent_byte_size > 0);
// base_addr += parent_byte_size - byte_offset;
base_addr += byte_offset;
bit_offset = 8*var_size - (bit_offset + bit_size);
bit_offset = 8 * var_size - (bit_offset + bit_size);
}

// printf("read %x, bit_offset %x, mask %x => %x\n", (int)data, (int)bit_offset,
// (int)((1 << bit_size) - 1),
// (int)(data >> bit_offset) & ((1 << bit_size) - 1));

#define _read_(_type_) \
do{ \
_type_ data = *((_type_*)base_addr); \
Expand Down Expand Up @@ -211,7 +207,7 @@ static int _entry_bitfield_write(metac_entry_t *p_memb_entry, void * base_addr,
// assert(parent_byte_size > 0);
// base_addr += parent_byte_size - byte_offset;
base_addr += byte_offset;
bit_offset = 8*var_size - (bit_offset + bit_size);
bit_offset = 8 * var_size - (bit_offset + bit_size);
}

#define _write_(_type_) \
Expand Down
45 changes: 2 additions & 43 deletions src/value_bitfields_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,8 @@
#include "value_base_type.c"
#include "value_with_args.c"

/*
little endian tests for pre-check. this is to debug lowleve first
DWARF 4, LE 1
fld a, data_bit_offset: 0, bit_size 2 => byte_offset 0, bit_offset 0
DWARF 4, LE 1
fld b, data_bit_offset: 2, bit_size 3 => byte_offset 0, bit_offset 2
DWARF 4, LE 1
fld c, data_bit_offset: 8, bit_size 5 => byte_offset 1, bit_offset 0
DWARF 4, LE 1
fld x, data_bit_offset: 13, bit_size 10 => byte_offset 1, bit_offset 5
DWARF 4, LE 1
fld z, data_bit_offset: 23, bit_size 22 => byte_offset 2, bit_offset 7
vs
DWARF 3, LE 1
fld a, bit_offset 6, bit_size 2, location 0 byte_size 1=> byte_offset 0, bit_offset 0
DWARF 3, LE 1
fld b, bit_offset 3, bit_size 3, location 0 byte_size 1=> byte_offset 0, bit_offset 2
DWARF 3, LE 1
fld c, bit_offset 3, bit_size 5, location 1 byte_size 1=> byte_offset 1, bit_offset 0
DWARF 3, LE 1
fld x, bit_offset 9, bit_size 10, location 0 byte_size 4=> byte_offset 1, bit_offset 5
DWARF 3, LE 1
fld z, bit_offset 19, bit_size 22, location 0 byte_size 8=> byte_offset 2, bit_offset 7
big endian:
DWARF 4, LE 0
fld a, data_bit_offset 0, bit_size 2 => byte_offset 0, bit_offset 0 bit_size 2
value 0: 00 00 00 00 00 00 00 00
read 0, mask 3
value 1: 40 00 00 00 00 00 00 00
read 0, mask 3
/home/runner/work/metac/metac/src/value_bitfields_test.c:130:F:default:pre_check:0: expected 1, got 0
DWARF 4, LE 1
fld a, data_bit_offset 0, bit_size 2 => byte_offset 0, bit_offset 0 bit_size 2
value 0: 00 00 00 00 00 00 00 00
read 0, mask 3
value 1: 01 00 00 00 00 00 00 00
read 1, mask 3
*/

#define PRECHECK_DEBUG
// uncomment the next line if the test doesn't work
// #define PRECHECK_DEBUG
struct {
char a:6;
char b:3;
Expand Down

0 comments on commit f928b9e

Please sign in to comment.