Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 92084495 authored by Ying Hsu's avatar Ying Hsu
Browse files

floss: fix duplicated reg_id while starting multiple advertising sets

Bug: 248113438
Tag: #floss
Test: ./buid.py --target test
Change-Id: I81a1d6b4b4195ffd62e45e26b1bcb2e1014146ed
parent c1bc5b3f
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -343,7 +343,7 @@ impl AdvertisingSetInfo {
        AdvertisingSetInfo {
            advertiser_id: None,
            callback_id,
            reg_id: REG_ID_COUNTER.fetch_and(1, Ordering::SeqCst) as RegId,
            reg_id: REG_ID_COUNTER.fetch_add(1, Ordering::SeqCst) as RegId,
        }
    }

@@ -469,6 +469,7 @@ impl Advertisers {
#[cfg(test)]
mod tests {
    use super::*;
    use std::collections::HashSet;
    use std::iter::FromIterator;

    #[test]
@@ -493,4 +494,14 @@ mod tests {
        AdvertiseData::append_adv_data(&mut bytes, 101, &[0]);
        assert_eq!(bytes, vec![6 as u8, 100, 0, 1, 2, 3, 4, 2, 101, 0]);
    }

    #[test]
    fn test_new_advising_set_info() {
        let mut uniq = HashSet::new();
        for callback_id in 0..256 {
            let s = AdvertisingSetInfo::new(callback_id);
            assert_eq!(s.callback_id(), callback_id);
            assert_eq!(uniq.insert(s.reg_id()), true);
        }
    }
}