<commit_before>#!/bin/sh
realtime start
python <<EOF
import hal
import os
h = hal.component("x")
try:
    ps = h.newpin("s", hal.HAL_S32, hal.HAL_OUT);
    pu = h.newpin("u", hal.HAL_U32, hal.HAL_OUT);
    pf = h.newpin("f", hal.HAL_FLOAT, hal.HAL_OUT);
    param = h.newparam("param", hal.HAL_BIT, hal.HAL_RW)
    h.ready()

    def try_set(p, v):
        try:
            h[p] = v
            print "set", p, v, h[p]
        except (ValueError, OverflowError):
            print "set", p, v, "fail"

    def try_set_pin(p, v):
        try:
            p.set(v)
            print "set", p.get_name(), v, p.get()
        except (ValueError, OverflowError):
            print "set", p.get_name(), v, "fail"

    try_set("s", -1)
    try_set("s", 0)
    try_set("s", 1)
    try_set("s", -1l)
    try_set("s", 0l)
    try_set("s", 1l)
    try_set("s", 0x7fffffff)
    try_set("s", -0x80000000)

    try_set("u", 0)
    try_set("u", 1)
    try_set("u", 0xffffffffl)

    try_set("f", 0)
    try_set("f", 0.0)
    try_set("f", 0l)
    try_set("f", -1)
    try_set("f", -1.0)
    try_set("f", -1l)
    try_set("f", 1)
    try_set("f", 1.0)
    try_set("f", 1l)

    try_set("f", 1l<<1023)


    try_set("s", 0x80000000)
    try_set("s", -0x80000001)

    try_set("u", -1)
    try_set("u", 1<<32)
    
    try_set("f", 1l<<1024)

    pin = h.getitem("s")

    def pin_validate(i, t, d):
        print "pincheck", i.get_name(), i.is_pin(), i.get_type() == t, i.get_dir() == d
    pin_validate(ps, hal.HAL_S32, hal.HAL_OUT)
    pin_validate(pu, hal.HAL_U32, hal.HAL_OUT)
    pin_validate(pf, hal.HAL_FLOAT, hal.HAL_OUT)

    pin = h.getitem("s")
    pin_validate(pin, hal.HAL_S32, hal.HAL_OUT)
    try:
        pin = h.getitem("not-found")
        print "getitem", "not-found", "ok"
    except:
        print "getitem", "not-found", "fail"

    pin_validate(param, hal.HAL_BIT, hal.HAL_RW)
    param = h.getitem("param")
    pin_validate(param, hal.HAL_BIT, hal.HAL_RW)

    try_set_pin(pu, 0)
    try_set_pin(pu, -1)
except:
    import traceback
    print "Exception:", traceback.format_exc()
    raise
finally:
    h.exit()
EOF
realtime stop<commit_msg>tests/halmodule.0: remove realtime start/stop around test<commit_after>#!/bin/sh
python <<EOF
import hal
import os
h = hal.component("x")
try:
    ps = h.newpin("s", hal.HAL_S32, hal.HAL_OUT);
    pu = h.newpin("u", hal.HAL_U32, hal.HAL_OUT);
    pf = h.newpin("f", hal.HAL_FLOAT, hal.HAL_OUT);
    param = h.newparam("param", hal.HAL_BIT, hal.HAL_RW)
    h.ready()

    def try_set(p, v):
        try:
            h[p] = v
            print "set", p, v, h[p]
        except (ValueError, OverflowError):
            print "set", p, v, "fail"

    def try_set_pin(p, v):
        try:
            p.set(v)
            print "set", p.get_name(), v, p.get()
        except (ValueError, OverflowError):
            print "set", p.get_name(), v, "fail"

    try_set("s", -1)
    try_set("s", 0)
    try_set("s", 1)
    try_set("s", -1l)
    try_set("s", 0l)
    try_set("s", 1l)
    try_set("s", 0x7fffffff)
    try_set("s", -0x80000000)

    try_set("u", 0)
    try_set("u", 1)
    try_set("u", 0xffffffffl)

    try_set("f", 0)
    try_set("f", 0.0)
    try_set("f", 0l)
    try_set("f", -1)
    try_set("f", -1.0)
    try_set("f", -1l)
    try_set("f", 1)
    try_set("f", 1.0)
    try_set("f", 1l)

    try_set("f", 1l<<1023)


    try_set("s", 0x80000000)
    try_set("s", -0x80000001)

    try_set("u", -1)
    try_set("u", 1<<32)
    
    try_set("f", 1l<<1024)

    pin = h.getitem("s")

    def pin_validate(i, t, d):
        print "pincheck", i.get_name(), i.is_pin(), i.get_type() == t, i.get_dir() == d
    pin_validate(ps, hal.HAL_S32, hal.HAL_OUT)
    pin_validate(pu, hal.HAL_U32, hal.HAL_OUT)
    pin_validate(pf, hal.HAL_FLOAT, hal.HAL_OUT)

    pin = h.getitem("s")
    pin_validate(pin, hal.HAL_S32, hal.HAL_OUT)
    try:
        pin = h.getitem("not-found")
        print "getitem", "not-found", "ok"
    except:
        print "getitem", "not-found", "fail"

    pin_validate(param, hal.HAL_BIT, hal.HAL_RW)
    param = h.getitem("param")
    pin_validate(param, hal.HAL_BIT, hal.HAL_RW)

    try_set_pin(pu, 0)
    try_set_pin(pu, -1)
except:
    import traceback
    print "Exception:", traceback.format_exc()
    raise
finally:
    h.exit()
EOF
{'fraction_non_alphanumeric': 0.18435105641978175, 'fraction_numerical': 0.03552356628743905, 'mean_word_length': 2.5224856909239577, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5364180', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1806, 'n_words': 364}